SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.

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.

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
ValueMeaning
"yyyy"Year
"m"Month
"d"Day
"h"Hour
"n"Minute
"s"Second
"w"Weekday
"ww"Week of the year
"q"Quarter
Further readings
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
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.