Date, Time, Hour, Now functions

These are handy VBScript functions that allow us to easily access date and times. They return a value taken from the computer's system clock.

The Date function

<%
Dim theDate 'create variable that will store the date
theDate=Date 'the Date function returns the date and we assign it to the variable
Response.write theDate 'write out the date
%>

The date is: 16/04/2014

The Time function

<%
Dim theTime 'create variable that will store the time
theTime=Time'the Time function returns the date and we assign it to the variable
Response.write theTime 'write out the time
%>

The time here in Ireland is: 15:03:10

The Now function

<%
Dim varNow 'create variable that will store date and time
varNow=Now 'the Now function returns the date & time - assign it to the variable
Response.write varNow 'write out the date and time
%>

The date and time is: 16/04/2014 15:03:10

Notice that all the functions above haven't any parameters passed in unlike the Hour function below.

The Hour function

The Hour function returns a number between 0 and 23 that represents the hour of the day.

<%
Dim theHour 'create variable that will store the hour
theHour=Hour(Now)'we pass in the Now function as a parameter
Response.write theHour 'write out the hour
%>

The hour here is: 15

Other date and time related tutorials:

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
Display the dates and times
Time and Date based greetings
IsDate Function
The DateDiff DateAdd and DatePart Functions

Get the best ASP hosting with DiscountASP.NET - great value, money back guarantee.

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