VistaDB 6
VistaDB / Developer's Guide / SQL Reference / Functions / Date and Time Functions / DATEDIFF
In This Topic
    DATEDIFF
    In This Topic
    INT DATEDIFF( datepart, startdate, enddate )

    Returns the number of intervals crossed between the two dates as specified by the Datepart. If you are interested in how many months are between two dates you would pass month as the datepart.

    Return Type
    Integer

    The following are valid datepart parameters:

    Datepart Abbreviations
    year yy, yyyy
    quarter qq, q
    month mm, m
    dayofyear dy, y
    day dd, d
    week wk, ww
    hour hh
    minute mi, n
    second ss, s
    millisecond ms



    Remarks

    NOTE: startdate is subtracted from enddate. If startdate is later than enddate, a negative value is returned.

    DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years.

    The method of counting crossed boundaries such as minutes, seconds, and milliseconds makes the result specified by DATEDIFF consistent across all data types. The result is a signed integer value equal to the number of datepart boundaries crossed between the first and second date.

    Example

    Result:  14
    
    
    Result: 104
    
    SELECT DATEDIFF(day, '01/01/2007', '04/15/2007')
    SELECT DATEDIFF(week, '01/01/2007', '04/15/2007')
    See Also