Writing Date and Time to a Page

ASP supports a number of commands deriving date and time information, from outputting the current date or time, or more specifically deriving, for example, the current year or even the name of the current month.

The table below details some of these data time related commands.

CommandDescription
date()Output is like: 17/2/2003  (format of the date will be dependant upon the settings of the server)
now()Output is like: 17/2/2003 1:28:18 PM (format of the date will be dependant upon the settings of the server)
Day(dateValue)Returns the day number.
WeekDayName(Day(dateValue))Returns the name of the specified day.
Month(dateValue))Returns the month number.
MonthName(Month(dateValue))Returns the month name.
Year(dateValue)Returns the year part of the date.

Over-ruling Server Settings

The server settings can be over-ruled, for example a server based in the US can be over-ruled to configure its date formatting to UK to English format.

The use of Session.LCID = 0413 sets the date format as dd/mmm/yyyy

A number of other date formatting commands are given in the table below.

CommandDescription
FormatDateTime(date(), vbGeneralDate)17/2/03 12:12:38 PM
FormatDateTime(curDate, vbLongDate)Monday, 17 February , 2003
FormatDateTime(curDate, vbShortDate)17/2/03
FormatDateTime(curDate, vbLongTime)12:12:38 PM
FormatDateTime(curDate, vbShortTime)12:12