Blog
Formula - How to get the dates for the current week
March 23. 2023
Do you need to retrieve the days of the current week? If so, this post shows the formula to carry out this task.
There are scenarios where it's necessary to calculate the days of the current week. The use case scenarios might be to set default values or to validate input values.
Here are the snippets of formula to carry out this task.
Get Monday of the current week
The basis of the calculations depends on the formula below. This returns the Monday of the current week.
DateAdd(Today(),The screenshot below highlights the result. At the time of writing (Thursday 23rd March 23), the Monday for the current week is Monday 20th March.
-(Weekday(Today(),StartOfWeek.MondayZero)),
TimeUnit.Days
)
Get Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday of the current week
Based on the logic above, we can simply add additional days to derive the dates for the remaining days of the week. For example, we would add 1 day to the above to find the date for the current Tuesday, 2 days for Wednesday, 3 days for Thursday, and so on.
// Get Tuesday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 1,
TimeUnit.Days
)
// Get Wednesday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 2,
TimeUnit.Days
)
// Get Thursday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 3,
TimeUnit.Days
)
// Get Friday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 4,
TimeUnit.Days
)
// Get Saturday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 5,
TimeUnit.Days
)
// Get Sunday for the current week
DateAdd(Today(),
-(Weekday(Today(),StartOfWeek.MondayZero)) + 6,
TimeUnit.Days
)
Conclusion
In cases where it's necessary to retrieve the days of the current week, we can use the formula that's highlighted in this post. .
- Categories:
- dates
Related posts
- Dates - How to convert a month name (eg January, Feburary, March) to month number (eg, 1, 2, 3)
- Dates - How to format date day numbers with suffix (st nd rd th)
- Dates - How to calculate UK tax weeks
- Dates - How to convert dates from MM DD YYYY to DD MM YYYY and vice versa
- Dates - How to detect overlapping times / scheduling conflicts
- Dates - How to display or convert Excel date serial numbers
- Dates - How to get the start date from week number
- Dates - How to check if a year is a leap year
- Dates - How to get the week number for a given date
- Dates - How to get the nth weekday for a month
- Dates - How to get the last weekday for a month
- Dates - How to get a numbered list of days or months, starting from a specified day or month
- Controls - How to display dates in a combo box
- Search - How to filter records by month and year using a delegable expression