# Can I programmatically tell if a date is a weekend or not?

I’m attempting to build a table of my team’s upcoming expected billing for projections. Entering each day and their expected logged time / project is overly tedious, so I’m attempting to create a button that at least helps with the repetitive nature of this.

I can’t share the doc at this time, but here’s my button code:

`Sequence(SelectedDates.First(),SelectedDates.Last()).FormulaMap(AddRow(Schedule, Schedule.Date, ToDate(CurrentValue), Schedule.Name, SelectedStaff.FormulaMap(CurrentValue), Schedule.Project, SelectedProject))`

This does a decent job of creating a loop that adds a new row for every date in the range with the defined staff member and project name (only one staff member at a time unfortunately). However, it includes ALL days in that range.

Is there a way to exclude weekends? I don’t see a function anywhere to parse whether a date falls on a weekend or not, so I’m hoping there’s a creative way to solve this. Otherwise I’ll be manually cleaning up afterwards…

Am sure this can be done. I’m not the expert many here are, but
We do have a function called networking days, which at least counts the working days between two days…

So you could just check each day before adding a row to see if it is a work day using this formula?
Or - you can test each day against a day name (since we can tell what day a date is with the weekdayname() or even easier potentially using the workkday() formulas

I’m figuring you can add an if to your statement just to check if the date you are about to add is a workday?
Cheers!

Hi Brendan,

Thanks for the response. Unfortunately, this function requires a range of dates and returns the total number of working days within that range, rather than answering “is this date a weekend?”

I suppose I can try making each row a single day range and seeing if it returns a zero? I’m not sure if that will work?

Hi @Keith_Guerrette,
you are right.

However this one-liner maybe helps: `[YourDate].Weekday()=7 || [YourDate].Weekday()=1`
It is just straightforward.
Let me know if it makes sense for you.

Cheers!

Edit.
To put it in a more actionable scenario, like “if it’s a weekend, postpone it to the next working day”:
`if([YourDate].Weekday()=7 || [YourDate].Weekday()=1, [YourDate].Workday(1), [YourDate])`

6 Likes