Date diff() Examples

Back to the Main Page

All of these examples assume that the library has been imported as noted in the Documentation.

Substracting one Date from Another

The diff() method of a date allows you to subtract one date from another and return the number of specified date parts between them. The default method ("Actual") returns the number of periods equal to the selected date part (number of 60-minute periods for hours, 24 hour-periods for days, etc).

The "Actual", "Logical" and "Complete" Options

The diff() method provides three distinct methods for determining differences in dates. These variations in these methods are subtle and care should be taken to understand the best method to apply to a given situation. The methods are:

The best way to understand these options is through examples:

Daylight Savings Time (DST) Considerations

The diff() method, by default, attempts to normalize seemingly nonsensical results due to DST (or the equivalent) changes. This behavior only affects date pairs where one of the two fall outside DST. This behavior can be overridden using the "NormalizeDST" parameter as in the following examples: