Date time calculations can be used to compare two dates, this can be done in 4 ways.
Uses System.DateUtils
Returns the amount of [timeframe] as integer between the 2 dates. The number is always rounded down.
Available time frames are year, month, week, day, hours, minute, second, millisecond.
Example:
Time frame: week, Date from: 2024-01-01, Date to: 2024-02-23
begin CompareTime := WeeksBetween(DateTimeFrom, DateTimeFrom); var DialogResult: Integer; end; |
Result: 7
Date span works the same as date between, only return a double rounded down to 2 decimals.
Example:
Time frame: week - Date from: 2024-01-01 - Date to: 2024-02-23
begin var CompareTime: Double; CompareTime := DaySpan(DateTimeFrom, DateTimeFrom); end; |
Result: 7.64
The compare calculation does not return an amount of something in between, but only a positive or negative integer based on witch date is older.
If the date from is later than the date to, the result is positive.
Example:
Date from: 2024-01-01 - Date to: 2024-02-23
begin var CompareTime: Integer; CompareTime := CompareDateTime(DateTimeFrom, DateTimeFrom); end; |
Result: -1
Date from: 2024-02-23 - Date to: 2024-01-01
begin var CompareTime: Integer; CompareTime := CompareDateTime(DateTimeFrom, DateTimeFrom); end; |
Result: 1
If the results are the same, the result will be 0
If you want to know if a date time is the same, and have the result in a directly boolean, use the Same date time calculation.
Example:
Date from: 2024-01-01 - Date to: 2024-01-01
begin var CompareTime: Boolean; CompareTime := SameDateTime(DateTimeFrom, DateTimeFrom); end; |
Result: true