Finding out difference in two dates by using DateDiff function
We 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.
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.
Dim d_diff
Response.Write "Today date is " & d_today & "<br>"
d_diff=DateDiff("m",#2/28/03#,#2/28/06#)
Response.Write "Difference " & d_diff & "<br>"
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