Sub DateDiff($date1 As DateTime, $date2 As DateTime, $type As String) As Integer


Returns an integer that specifies the difference between two specified date values. The result is always a positive value, regardless of whether $date1 or $date2 is more recent.


If you need to determine which date is more recent, you can compare them in an if statement. For example:


$d = iif($date1 > $date2, $d, -$d)


Parameters


  • $date1 ... Date expression.
  • $date2 ... Date expression.
  • $type ... String expression.


$type can have one of the following values


  • y ...Calculates the number of years between $date1 and $date2.
  • m ... Calculates the number of months between $date1 and $date2.
  • d ... Calculates the number of days between $date1 and $date2.
  • h ... Calculates the number of hours between $date1 and $date2.
  • n ... Calculates the number of minutes between $date1 and $date2.
  • s ... Calculates the number of seconds between $date1 and $date2.


Example:

Dim $i

' Encode a date/time
$i = EncodeDateTime(2023, 11, 10, 12, 0, 30)

' Calculate number of days between two dates
$i = DateDiff(Now, $i, "d")