Finding out difference in two dates by using DateDiff functionWe can find out the difference between two dates by using DateDiff function of VBScript used in ASP. DateDiff() finds out the difference of the dates based on the required date part like month, year, days etc. Here is the basic syntax of DateDiff function.
DateDiff(date_type, date1, date2, first_dow, first_woy)Here date_type is the date part to be considered while returning the output. This can be month, day, year etc. The table with different values of date_type is listed at the end. Next two arguments date1 and date2 are two date values for which difference is to be calculated. The other two arguments first_dow and first_woy are optional arguments. First_dow takes the value to specify what is to be taken as first day of the week and the other value first_woy takes the value of first week of the year.
Let us see this example code on uses of DateDiff to find out difference in months between two dates.
The output of the above by changing the value of date_type we can find out the difference in days, years, weeks etc.
Table for different date_type values
|"ww"||Week of the year|
Be the first to post comment on this article :
|ASP Date & Time Functions|
Getting todays Date and Time based on local settings|
Formatting date and time on local settings
Adding Date intervals using DateAdd function
Finding difference between two dates using DateDiff function
Collecting parts of Date by using DatePart function
Collecting Month name by using Month number by MonthName function
Collecting Name of the weekday of any Date by WeekDayName function
Generating Date variables by using Month, Day and Year Value
Function IsDate to check valid date or date variable
Checking user entered date value