Working with Date and Time data is very common in any ASP web application. In this tutorial, we will cover how to properly use the various ASP Date related functions. In addition, we will take a closer look into the different formatting options that are available for you to use.
ASP provides a number of built-in date-related functions that can be used to find the current date and time. The three most common functions are
<% Response.Write "Today's date is " & date() & "<br />" Response.Write "The current time is " & time() & "<br />" Response.Write "The date and time is " & now() & "<br />" %>
FormatDateTime function can be used to format the results from the date-related function. You can pass an optional integer ranging from
0– This is the default setting.
1– long date defined by the regional settings.
2– short date defined by the regional settings.
3– time format defined by the regional settings.
4– time format using military time HH:MM.
<% Response.Write(FormatDateTime(Date,0) & "<br />") Response.Write(FormatDateTime(Date,1) & "<br />") Response.Write(FormatDateTime(Date,2) & "<br />") Response.Write(FormatDateTime(Now,3) & "<br />") Response.Write(FormatDateTime(Now,4) & "<br />") %>
Date and Time Functions
ASP (VBScript) also provides a number of date- and time-related functions that are very useful. The
DatePart function is also very useful. It allows you to retrieve a specific part of a date/time value.
|Returns the year portion from date.|
|Returns the month portion from the date.|
|Returns a string. Optional |
|Returns the day portion from the date.|
|Returns the hour portion from time.|
|Returns the minute portion from time.|
|Returns the second portion from time.|
|Returns the current year.|
|Returns the current quarter.|
|Returns the current month.|
|Returns the week # of the year.|
|Returns the current hour.|
|Returns the current minute.|
|Returns the current second.|