# Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

# (Nearest) Weekday function

#### Rick Reinckens

Here's the task I'm trying to solve and something like an @weekday[date, [before|after], [format]] might be useful:

Problem:
1. Certain reports are due on 1st and 15th of month.
2. Certain preparations have to be done 1 business day before.
3. The user needs a warning 2 business days before (i.e., "Need to prep tomorrow. Report due on 15th.)
4. BUT if the 1st or 15th falls on a weekend the reports are sent the next business day. (E.g., report sent Monday 17th.)
5. The warnings have to be on business days--a warning on Saturday the 15th won't be seen.
Assumptions:
1. "Business" day means Monday-Friday. The function wouldn't handle holidays.
2. Reports might have to be filed on or before the 1st and 15th rather than the next business day after.
3. January (e.g.) and February would cause problems--you can't just pop up on the 27th, 28th, etc., "1st of Month report due." Users would get annoyed having the "2 day" warning pop up for 4 days and some would start ignoring it.

On the other hand, if the 1st is a Monday, then having it pop up on the 27th might not have it seen for 4 days.
Function:
1. @weekday[date, [before|after], [format]]
2. Echo %@weekday[date] would display date if it is a weekday or -1 (or 0, etc.) if it's not.
3. Echo %@weekday[date, "before"] (or more likely, 0 or 1) would display date if it is a weekday. If date is a weekend, it would display the nearest weekday before date.
4. You might want to have 2 "format" parameters--one for the format of date and one for the format of the return value.
Incidentally, this is a problem I'm trying to solve, so whether such a function is added to TCC or not I would appreciate some suggestions on how to set this up. I need reports sent on or after the 1st and 15th.

It's not exactly what you are looking for, but I just added some week, month, quarter aliases here. You might be able to get some ideas from them.

You seem to have 4 dates to handle in the course a given month:

• the report on 1
• the report on 15
these should be put forward 1 or 2 days if falling on a weekend

• the prep on 13
• the prep ad the end of the month
these should be put back 1 or 2 days if falling on a weekend.

I could envision 4 short DO loops, probably using the numeric value @DATE gives you for a given date, to test for weekdayness :-)

E.g., for the first 3 days of a month, if the day is a weekday, set a flag and leave loop.

For the last prep test, you'd need 2 tests: 1 for weekday, one for still being the same month. You'd have to start on the 26 looping to 31, using the last date that fullfills both weekdayness and correctmonthiness.

I haven't worked this out in detail, but it looks like this is the approach, using Charles Dye's @INLIEU function:

Set DueDate=8/15/2017 (Saturday)

Set DueDate=@INLIEU[DueDate, after] (returns Monday 8/17/2017)
Set PrepDate=@INLIEU[DueDate - 1, before] (returns Friday 8/14)
Set WarnDate=@INLIEU[PrepDate -1, before] (returns Thursday 8/13)

Replies
7
Views
1K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
0
Views
1K
Replies
0
Views
2K
Replies
5
Views
3K
Replies
0
Views
2K
Replies
0
Views
2K
Replies
3
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
12
Views
4K
Replies
0
Views
2K
Replies
13
Views
6K
Replies
9
Views
3K
Replies
0
Views
3K
Replies
4
Views
4K
Replies
4
Views
4K
Replies
0
Views
3K
Replies
0
Views
3K
Replies
2
Views
3K
Replies
2
Views
5K
Replies
0
Views
3K
Replies
3
Views
4K