Data Format Expression

Posted on 2003-11-06
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

Question by:Moizsaif123
LVL 44

Expert Comment

Comment Utility
what database are you using?


Expert Comment

Comment Utility
something like this

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

~ fantasy ~
LVL 76

Expert Comment

Comment Utility
This works for a Jet (Access) DB:

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


Author Comment

Comment Utility
The format syntax did not work for me and I am using oracle database, if that helps

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.


Author Comment

Comment Utility

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)


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

Accepted Solution

p_hip earned 120 total points
Comment Utility
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 ?


Expert Comment

Comment Utility
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.

Expert Comment

Comment Utility
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)

Author Comment

Comment Utility
I can use To_char to convert the date datatype to string and then use the mm/dd/yyyy format

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now