Return To Home Page
Formating Date & Time
Often when using ASP or Active Server Pages you will find it necessary to format the way your date and time variables are displayed. Luckily there is a built in vbscript function called FormatDateTime that does all the work for you.
Here are some simple examples of using the functions with your variables.
Run these from any ".asp" page and watch what happens
<%= FormatDateTime(Date) %><br>
<%= FormatDateTime(Date, 0) %><br>
<%= FormatDateTime(Date, 1) %><br>
<%= FormatDateTime(Date, 2) %><br>
<%= FormatDateTime(Now, 3) %><br>
<%= FormatDateTime(Now, 4) %><br>
<%= FormatDateTime(Now) %><br>
You should get values similar to this.
(They will be based on the current date when you run them though.)
4/18/2005
4/18/2005
Monday, April 18, 2005
4/18/2005
2:08:24 PM
14:08
4/18/2005 2:08:24 PM
In case you are wondering the date formats will adjust based on the regional or LCID settings of your web server. These examples are using USA format.
Then, in the examples below we use some of the built in VBScript Constands with the function.
(it really does the same thing as the number values, but these are easy to remember)
<%= FormatDateTime(Date) %><br>
<%= FormatDateTime(Date, vbGeneralDate) %><br>
<%= FormatDateTime(Date, vbLongDate) %><br>
<%= FormatDateTime(Date, vbShortDate) %><br>
<%= FormatDateTime(Now, vbLongTime) %><br>
<%= FormatDateTime(Now, vbShortTime) %><br>
<%= FormatDateTime(Now) %><br>
ASP
(Active Server Pages) is a technology developed by Microsoft. Pages using ASP
are primarily developed in JScript, or VBScript and are integrated into the
HTML of your Web pages. The ASP code is compiled on-the-fly by the server and
the resulting output is standard HTML. By using ASP, Web pages can be dynamic,
full of ever-changing content, and browser independent.