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.

Built-in Functions

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 date(), time(), and now().

<% Response.Write “Today’s date is " & date() & “
” Response.Write “The current time is " & time() & “
” Response.Write “The date and time is " & now() & “
” %>

FormatDateTime Function

The FormatDateTime function can be used to format the results from the date-related function. You can pass an optional integer ranging from 0 through 4.

  • 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) & “
”) Response.Write(FormatDateTime(Date,1) & “
”) Response.Write(FormatDateTime(Date,2) & “
”) Response.Write(FormatDateTime(Now,3) & “
”) Response.Write(FormatDateTime(Now,4) & “
”) %>

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.