The 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)
| Interval | Description: |
| yyyy | Year |
| q | Quarter |
| m | Month |
| y | Day of year |
| d | Day |
| w | Weekday |
| ww | Week of year |
| h | Hour |
| n | Minute |
| s | Second |
Output: 74 Months
The 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:
| Interval | Description: |
| yyyy | Year |
| q | Quarter |
| m | Month |
| y | Day of year |
| d | Day |
| w | Weekday |
| ww | Week of year |
| h | Hour |
| n | Minute |
| s | Second |
Output:
15/05/2010
'this is UK format as the server is in the UK
Output: 18:58:25
We 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:
| GetPartoftheDate | Description: |
| yyyy | Year |
| q | Quarter |
| m | Month |
| y | Day of year |
| d | Day |
| w | Weekday |
| ww | Week of year |
| h | Hour |
| n | Minute |
| s | Second |
OutPut:
The Now function returns:15/03/2010 19:23:25
Retrieve the year: 2010
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
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%