Solved

Data Format Expression

Posted on 2003-11-06
9
1,813 Views
Last Modified: 2012-06-27
My Problem deals with Data Formatting expression of the Date value I get from the Database
The data that comes from the DataBase as the Date is like

Sat, Nov 15 2003 09:15 am, now I want to change the format to MM/DD/YYYY and get rid of the time(the "09:15 am").....Can I just do that in the query?

My query is like this:

SELECT DisplayDate FROM TableName



0
Comment
Question by:Moizsaif123
9 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9697875
what database are you using?

AW
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9698353
something like this

formatted = Format(rs.Fields("DisplayDate"), "MM/DD/YYYY")

~ fantasy ~
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9699530
This works for a Jet (Access) DB:

rs.Open "SELECT Format$(Mid$([DisplayDate], 5),'mm/dd/yyyy') AS FormattedDate FROM TableName;", MyConnection, adOpenDynamic, adCmdText


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Moizsaif123
ID: 9701574
The format syntax did not work for me and I am using oracle database, if that helps


0
 
LVL 4

Author Comment

by:Moizsaif123
ID: 9701751
GrahamSkan,

The error I get when I use the code, SELECT Format$(Mid$([DisplayDate], 5),'mm/dd/yyyy') AS FormattedDate.....or

Select Format(DisplayDate,'MM/DD/YYYY') As DisplayDate is something like this:

Server Error in '/Patients-Web-Proj' Application.
--------------------------------------------------------------------------------

One or more errors occurred during processing of command. ORA-00936: missing expression
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: One or more errors occurred during processing of command. ORA-00936: missing expression

Source Error:


Line 103:                Cn.Open()
Line 104:                myAdaptor.SelectCommand = cmd
Line 105:                myAdaptor.Fill(DataSet1)
Line 106:                DataGrid1.DataSource = DataSet1
Line 107:                DataGrid1.DataBind()
 

Source File: c:\inetpub\wwwroot\Patients-Web-Proj\Appointment.aspx.vb    Line: 105

Stack Trace:


[OleDbException (0x80040e14): One or more errors occurred during processing of command.
ORA-00936: missing expression]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   Patients_Web_Proj.Appointment.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Patients-Web-Proj\Appointment.aspx.vb:105
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET Version:1.0.3705.288
0
 

Accepted Solution

by:
p_hip earned 120 total points
ID: 9705056
If the db is Oracle and the column is held on the db as a 'Date' data type then use "select to_char(col1, 'mm/dd/yyyy')......" if you want the result as a string - or have I misunderstood what you want ?

Paul.
0
 
LVL 1

Expert Comment

by:fsaims
ID: 9706385
Hi Buddy You cannot use Format$ function in SELECT Statement. This is another solution, you can change the date format in regional settings (Control Panel), if u r using Windows Operating System.
0
 
LVL 1

Expert Comment

by:fsaims
ID: 9706401
All grid formatting is centered about the TableStyles collection accessible via the grid property window. Here is how it works:

A style defines most of the grid formatting properties, including column format (via a collection called GridColumnStyles)
At any given moment the grid adheres to one style selected according to the style MappingName property
Once you understand this, many of the basic tasks are,well basic. Here are some examples:

Column caption, width, Read/Write, control type(text box / check box) and more are defined in the column style.
Column order is determined by GridColumnStyle order.
If we want to "hide" a column - we dont map it to any column style.
The only trick left is to determine the right mapping name:

When grid shows a DataSet DataTable use the table name as defined in the schema
When grid shows an object data structure use the structure data type (i.e. ArrayList)
0
 
LVL 4

Author Comment

by:Moizsaif123
ID: 9707046
I can use To_char to convert the date datatype to string and then use the mm/dd/yyyy format
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 84
passing a value with stream reader AFTER a ";" 3 83
Send outlook email from VBS Script 2 59
checkbox to hide entire section 10 62
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question