Solved

Data Format Expression

Posted on 2003-11-06
9
1,812 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 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