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 04/02/2012 04:42:32

<%= Date() %> prints out 04/02/2012

<%= Now() %> prints out 04/02/2012 04:42:32

<%= Time() %> prints out 04:42:32

<%= FormatDateTime(strNow, vbGeneralDate) %> prints out 04/02/2012

<%= FormatDateTime(strNow, vbLongDate) %> prints out 04 February 2012

<%= FormatDateTime(strNow,vbShortDate) %> prints out 04/02/2012

<%= FormatDateTime(strNow, vbLongTime) %> prints out 04:42:32

<%= FormatDateTime(strNow, vbShortTime) %> prints out 04:42

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

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

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

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

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

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

<%= 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 hosting provider from web-hosting-top.com and save up to 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.

Global ASP.NET Hosting Leader - Click Here