Solved

Data Format Expression

Posted on 2003-11-06
9
1,809 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

770 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