![]() |
|
|
The DateDiff, DateAdd and DatePart VBScript FunctionsThe Datediff functionThe Datediff function is a great way to calculate the interval period between two dates. If you set the interval parameter to m for months the function will return the amount of months between the two dates. The table below lists the interval periods you can set for the interval parameter. Syntax: DateDiff(Interval,date1,date2)
<%
Response.write DateDiff("m","01/01/04",date) & " Months" 'date function returns todays date so its difference between 01/01/04 & today %> Output: 52 Months The DateAdd functionThe DateAdd() functions allows us to add or subtract from a date or time. DateAdd returns a date or time that has been modified by the number parameter. Syntax: DateAdd(Interval, number, Date) The interval argument accepts the following values:
<%
Response.write DateAdd("m",2,date) 'the date function returns today's date so we are adding 2 months on 'you can also substract i.e. -2 %> Output:
12/07/2008
<%
Response.write DateAdd("n",-25,time) 'the time function returns today's time so we are substracting 25 minutes %> Output: 04:32:14 The DatePart functionWe can use the DatePart function to return the specified part of the date and time. Syntax: DatePart(GetPartOftheDate, Date) The GetPartoftheDate argument accepts the following values:
<%
Response.write "The Now function returns:" & Now & "<br>" Response.write "Retrieve the year: " & DatePart("yyyy", Now) %> OutPut:
The Now function returns:12/05/2008 04:57:14 Other date and time related tutorials:
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|