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 31/07/2010 13:21:26

<%= Date() %> prints out 31/07/2010

<%= Now() %> prints out 31/07/2010 13:21:26

<%= Time() %> prints out 13:21:26

<%= FormatDateTime(strNow, vbGeneralDate) %> prints out 31/07/2010

<%= FormatDateTime(strNow, vbLongDate) %> prints out 31 July 2010

<%= FormatDateTime(strNow,vbShortDate) %> prints out 31/07/2010

<%= FormatDateTime(strNow, vbLongTime) %> prints out 13:21:26

<%= FormatDateTime(strNow, vbShortTime) %> prints out 13:21

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

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

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

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

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

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

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

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

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

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

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

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