Solved

Data Format Expression

Posted on 2003-11-06
9
1,814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

717 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