Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript DateDiff Function

VBScript DateDiff Function


VBScript reference manual Complete VBScript Reference Manual


The DateDiff function returns the number of time intervals between two dates.

Syntax

DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])

Parameters Description
interval Required. The unit of time interval used to calculate the difference between date1 and date2.

The following values can be used:

  • yyyy - year
  • q - quarter
  • m - month
  • y - day of the year
  • d - day
  • w - day of the week
  • ww - week of the year
  • h - hour
  • n - minute
  • s - Seconds
  • | | date1,date2 | Required. Date expressions. The two dates to be used in the calculation. | | firstdayofweek | Optional. Specifies the day of the week, that is, which day is the first day of the week.

    The following values can be used:

    | | firstweekofyear | Optional. Specifies the first week of the year.

    The following values can be used:

    |

    Example

    Example 1

    The difference between January 31, 2009 and January 31, 2010:

    The example above produces the following output:

    1

    4

    12

    365

    365

    52

    53

    8783

    527039

    31622340

    Try it »

    Example 2

    How many weeks between December 31, 2009 and December 31, 2012 (starting on Monday):

    The example above produces the following output:

    156

    Try it »


    VBScript reference manual Complete VBScript Reference Manual