Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying a datetime sql field !?!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Why when in my database i have a datetime of 2002-12-31 00:00:00.000 does it write the screen in ASP as 12/31/02?

Why cant you enter a date as 2002-12-31 and display it as that???

Please Help.
 
unless you state how the it is to be formatted then that will be the default format. Here's a example of formatting the date/time

<%
Dim dToday, dXmas2001

Response.Write &quot;Today's date: &quot; & fmtDateTime(Now(), &quot;yyyy-mm-dd&quot;)
' date displayed: 2001-07-19

Response.Write &quot;Yesterday's date: &quot; & fmtDateTime(DateAdd(&quot;d&quot;, -1, Now()), &quot;yyyy-mm-dd&quot;)
' date displayed: 2001-07-18

dXmas2001 = #12/25/2001 12:45:50#
Response.Write &quot;Christmas 2001: : &quot; & fmtDateTime(dXmas2001, &quot;m/dd/yyyy hh:mm&quot;)
' date/time displayed: 12/25/2001 12:45
%>

provide tools to let people become their best.
 
If you are using SQL Server as your database, you can format the date for display at the database level, which gives you more control over the display format.

SELECT CONVERT(varchar,date_field,111) FROM tblDate

will give you the format of yyyy/mm/dd
or changing the 111 to 120 will give you yyyy-mm-dd hh:mi:ss

Check the SQL Server BOL under CONVERT for more formats.


The VBScript date formatting function is much more limited, but here is a reference for that as well:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top