Reg Exp
Web Design
Notes Client
Find all the Mondays in a date range
You may have a need to find all the Mondays (or Fridays, or a certain weekday) in a given date range. This code will allow you to do that. First, get an array containing all the dates in the range. This is actually easier than it sounds. Let's say you want the range January 1st, 2003 until December 31st, 2003. You can do that in one line:

DateList := @TextToTime(@Explode([01/01/2003-12/31/2003]));

If you want the date range to be a bit more dynamic, you can do that in two statements:

Range := @TextToTime(@Text(@Date(***; ***; ***); "D0S0") + "-" + @Text(@Date(***; ***; ***); "D0S0")));
DateList := @TextToTime(@Explode(Range));

(Remember to substitute the correct computed values for the ***'s to get the dynamic dates)

Once you have the DateList variable populated (it contains multiple values of all the dates), then it's a matter of keeping only the ones with the correct weekday (Monday in our example).

DatePlusWeekday := @Text(DateList) + "%" + @Text(@Weekday(DateList));
@Trim(@Left(DatePlusWeekDay; "%2"))

The first statement above expands on the multiple value DateList variable. DatePlusWeekday will have the date, then a percent sign, then the number of the weekday for each date. The final statement takes everything to the left of the percent sign plus the weekday to keep (2 = Monday). For 6 of every 7 days, the @Left will result in a null value. For the 7th (the Mondays), the @Left will result in the date only (the percent sign and the weekday number will be removed). The @Trim removes all the null values, resulting in just the dates that are Mondays in the date range.