How to derive weekdays from a date

If you need to derive the weekday from a date field or the Date Picker, you can use the following formula:
image

How does this work?
When calculating with a date field we get a decimal number as a result.
(see: How to calculate with days and minutes)

For example:
image
The 7th of July 2020 is represented by the value 18449.9166.
Where 18449 is the number of days since 1/1/1970 and the decimal 0.9166 a fraction of a day to represent the time.

Adding 4 days
In our formula we first add 4 days to the Date Picker value:
image
image
Why?
Because the 1/1/1970 - day zero - was a Tuesday. And in the calculation, we want to end up with Monday as 1, Tuesday as 2, etc.
By adding 4 we are adjusting the number for the weekday we will get at the end of the calculation.

For more background please see e.g. date - How to calculate the day of the week based on unix time - Stack Overflow

Simulating a Modulo Operation
The next trick is to simulate a Modulo function (which we don’t have available in Adalo).
This can be done using the following formula:
image
Don’t get confused: It is basically to find out the remaining number of days after the division with 7 (days per week).

Basically, we take the number of days and divide it by 7.
In the result we get 2636 full weeks = 18452 days and a remainder of 0.2738… weeks = 1.91 days:

image

The remainder of the days is the part we are interested in.
We round the 1.91 up to 2 days, which corresponds to the second day after a full week = Tuesday.

We now have the weekday available to filter for example on time slots open for booking on a selected date.:
Available slots for day 2, Tuesday:


Available slots for day 4, Thursday:

10 Likes

Awesome! Thanks for sharing!

3 Likes

@karimoo I have tried the custom formula. I didnt get the correct value. I think the formula may be wrong.
Screenshot 2021-07-04 at 2.03.55 AM

Do you have a clone to share?

Hi @ron,

I’m using this in some of my apps (sorry can’t allow cloning them as they are for my customers), formula seems to work.

One note - for the time zones to the west of GMT, it gives 0 for Sundays; for east of GMT, it gives 7 for Sundays.

Best regards, Victor.

2 Likes

Hello karimoo,
In your sentence “If you need to derive the weekday from a date field or the Date Picker, you can use the following formula:” what do you call a “Date Field” ? Sorry if the question seems a bit stupid…
I’m trying to make a list of events appear by selecting a list of moments (such as “this week-end, tomorrow…”). I can’t find a way to list events for this weed-end, whatever day of the week we are… And I don’t want to use a Date Picker. Anyone has an idea ? Thank you

Hey @Victor ,

I’m here in the California, USA and I can’t seem to get the formula to work properly. During the weekdays the formula was sorta working, but now it’s Saturday and there is no data for that day on display. I’m using the formula to show specific info about something each day.

If you could help me with this or even provide screenshots of your working formula, I’d really appreciate it man.

Thanks!