ASP has a very handy inbuild function called FormatDateTime().
Let's start with the now() function to get the current date and time into a variable
<%
dim todaysDate
todaysDate=now()
%>
Now we can use the FormatDateTime function to format our date variable in a variety of ways.
First let's see how todaysDate appears :
<%
Response.write todaysDate
%>
RESULT: 2/14/2005 12:34:41 PM
Using 0 - the vbGeneralDate format creates a date as short date (if included), and time as long time.
<% Response.write FormatDateTime(todaysDate,0)
%>
RESULT: 2/14/2005 12:34:41 PM
Using 1 - the vbLongDate shows the date as long date
<%
Response.write FormatDateTime(todaysDate,1)
%>
RESULT: Monday, February 14, 2005
Using 2 - the vbShortDate shows the date as short date
<%
Response.write FormatDateTime(todaysDate,2)
%>
RESULT: 2/14/2005
Using 3 - the vbLongTime format shows the time as long time .
<%
Response.write FormatDateTime(todaysDate,3)
%>
RESULT: 12:34:41 PM
Using 4 - the vbShortTime format creates the current time in 24 format (hh:mm)
<%
Response.write FormatDateTime(todaysDate,4)
%>
RESULT: 12:34
International Date and Time
You can use the session.lcid property to change the formatting of the date and time.
For example
<%session.lcid=2057%>
will set the date and time to UK format (DD/MM/YYYY instead of MM/DD/YYYY ) Here's a list of international locales. Bear in mind that setting these will also change currency formatting.
ASP has a very handy inbuild function called FormatDateTime(). Lets start with the now() function to get the current date and time into a variable <% dim todaysDate todaysDate=n