How would I test if date is in date range (both strings)?

date-range, delphi

Solution

You can use the unit `System.DateUtils` and its function DateInRange:

var
  dStart, dEnd, d2Test: TDate;
begin
  dStart := StrToDate('25/07/2012');
  dEnd   := StrToDate('29/07/2012');

  d2Test := StrToDate('26/07/2012');

  if DateInRange(d2Test, dStart, dEnd) then
    ShowMessage('In range!');

You can also check the fourth parameter of this function (`AInclusive: Boolean = True`)... depending on your need...

Problem

I have two strings, for example `05.04.2002` and `23.01-2002 - 23.06.2002`. How would I find out if the date in my first string is between the dates in the second string? What I have been thinking ``` dateString := '05.04.2002'; dateRangeString := '23.01-2002 - 23.06.2002'; date := StrToDate( dateString ); rangeStart := StrToDate( LeftStr(dateRangeString, 10) ); rangeEnd := StrToDate( RightStr(dateRangeString, 10) ); ``` Now from there I don't know what to do!

Original source