Formatting ASP date yyyy-mm-dd hh:mm:ss

Hi
I need my date formatted like:
yyyy-mm-dd hh:mm:ss
Is there a function for this?

Thanks!
JuniorBeeAsked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
Sorry...assumed ASP.Net.

Using VBScript with older ASP you would need to use the Year(), Day(), Month(), etc. functions to get the pieces of a Time variable.

Dim currentTime

currentTime = Now
Response.Write Year(currentTime) & "-" & Month(currenTime) & "-" & Day(currentTime) . . . etc.
0
 
Todd GerbertIT ConsultantCommented:
Yes, check documentation for the .ToString method of the DateTime object.

DateTime dt = DateTime.Now;
Response.Write(dt.ToString("yyyy-MM-dd HH:mm:ss"));

Dim dt As DateTime = DateTime.Now
Response.Write(dt.ToString("yyyy-MM-dd HH:mm:ss"))
0
 
roblickleyCommented:
How will the date and time be presented to the function.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.