Displaying and formatting Dates and Times

Just to clear up an issue, the date and time displayed on this page are provided by my server so may not be the same where you are. Some of the dates are displayed in UK format ie dd/mm/yyyy rather than the American mm/dd/yyyy, though they'll display correctly according to where your server is located.

<% strNow=Now()' this variable will be used later below %>

strNow holds the value 15/03/2010 19:26:06

<%= Date() %> prints out 15/03/2010

<%= Now() %> prints out 15/03/2010 19:26:06

<%= Time() %> prints out 19:26:06

<%= FormatDateTime(strNow, vbGeneralDate) %> prints out 15/03/2010

<%= FormatDateTime(strNow, vbLongDate) %> prints out 15 March 2010

<%= FormatDateTime(strNow,vbShortDate) %> prints out 15/03/2010

<%= FormatDateTime(strNow, vbLongTime) %> prints out 19:26:06

<%= FormatDateTime(strNow, vbShortTime) %> prints out 19:26

<%= Year(strNow) %> prints out 2010

<%= Month(strNow) %> prints out 3

<%=Day(strNow) %> prints out 15

<%=Hour(strNow) %> prints out 19

<%=Minute(strNow) %> prints out 26

<%=Second(strNow) %> prints out 6

<%= WeekDay(strNow) %> prints out 2

<%= WeekDayName(WeekDay(strNow)) %> prints out Monday

<%= WeekDayName(WeekDay(strNow), 1) %> prints out Mon

Other date and time related tutorials:
Read more on the Date, Time and Now VBScript functions
Here's a code snippet to display the day and date (eg. Mon 25 December).
Here's a code snippet to display the day and date with the ordinal suffix (eg. Mon 25th December).
How to get the current month name
Time and Date based greetings
IsDate Function
The DateDiff DateAdd and DatePart Functions

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Get your best asp web hosting provider now and save 25%