/ lang / datediff
DateDiff
Syntax

    Count = DateDiff ( Date1 AS Date , Date2 AS Date , Period AS Integer ) AS Integer

Returns the number of periods between two dates.

- Date1 is the upper date.
- Date2 is the lower date.
- Period is the kind of period: year, month, day, week...

The number of periods is returned.

Period can be one of the following constants:

Constant | Effect
--- | ---
`gb.second` | Return the number of seconds.
`gb.minute` | Return the number of minutes.
`gb.hour` | Return the number of hours.
`gb.day` | Return the number of days.
`gb.week` | Return the number of weeks.
`gb.weekday` | Return the number of week days (ignore Saturday and Sunday).
`gb.month` | Return the number of months.
`gb.quarter` | Return the number of quarters.
`gb.year` | Return the number of years.

Only entire periods are returned. The result is round down.

### Examples

    PRINT DateDiff("01/02/2005 12:55:00", "01/01/2005", gb.Day)
    <hr>-1

This example shows how DateDiff works internally

    DIM date1 AS Date
    DIM date2 AS Date
    DIM fDiff AS Float
    DIM iDiff AS Integer

    date1 = Date(1964, 02, 28, 0, 29, 0)
    date2 = Date(1964, 03, 01, 0, 30, 0) ' one minute more than two days
    fDiff = CFloat(date2) - CFloat(date1)
    iDiff = Int(fDiff * 24)
    PRINT "first  : "; fdiff; "  int:"; idiff; "  DateDiff:"; DateDiff(date1, date2, gb.Hour)
    date1 = Date(1964, 02, 28, 0, 30, 0)
    date2 = Date(1964, 03, 01, 0, 29, 0) ' one minute less than two days
    fDiff = CFloat(date2) - CFloat(date1)
    iDiff = Int(fDiff * 24)
    PRINT "second : "; fdiff; "  int:"; idiff; "  DateDiff:"; DateDiff(date1, date2, gb.Hour)

    <hr>first  : 2.000694444403  int:48  DateDiff:48
    second : 1.999305555597  int:47  DateDiff:47

### See also

Date & Time Functions