Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is date within any date range in a dynamic array of date ranges

Status
Not open for further replies.

PJ222

Technical User
May 11, 2023
2
CA
Hi,
I have a string containing multiple date ranges separated by <br> (number of date ranges varies for 1 to ?)
I need to evaluate if a specific date is within any of the date ranges and return true if the date is in any date ranges.

string ex. Jan 1 2020-Apr 2 2020<br>Nov 3 2021-Dec 2 2022<br>

so i have startdate + "-" + enddate<br> making up the date ranges the date ranges do not overlap.

The end result is a formula i can use to select records for a crystal report where formula is not true ( i dont want the record if the specific date is in any of the date ranges.

Thanks for any help.
 
Figured this out using hardcoded values as a test.
local stringvar ranges :="Jan 1 2020-Apr 2 2020<br>Nov 3 2021-Dec 2 2022";
local numbervar result:=-1;
local datevar checkdt := date("Jan 4 2020");
local datevar startdt ;
local datevar enddt;
stringvar array dates := split(ranges,"<br>");

Numbervar i;
for i := 1 to Ubound(dates) do (
startdt:=date(Mid(dates, 1, inStr(dates, "-")-1));
enddt:=date(MID(dates,INSTR(dates, "-")+1));
If checkdt in startdt to enddt then
result:=0;
exit for

);
result
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top