J
J
Jack Cooper2016-07-11 16:59:06
PHP
Jack Cooper, 2016-07-11 16:59:06

How to get specific days of the week in a date period?

Good day everyone.
Prompt how to implement on more compactly.
I need in the period for example from 07/11/2016 to 07/31/2016 to select the dates of all, for example, Mondays.
The result for example will be 11-07-2016, 18-07-2016, 25-07-2016.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Makarov, 2016-07-11
@negmat

If the selection condition is dynamic, then just go through all the dates from the range and check for a specific condition.
If Mondays, then we find the first Monday from the range, push the date in a week until we leave the range.
Use the Datetime class's format() method to view specific date parameters.

R
Rsa97, 2016-07-11
@Rsa97

1. Get the day of the week of the start date.
2. If it's not Monday, then calculate the offset to Monday in days, add the offset to the start date.
3. From the start date with a step of 7 days, go to the end date.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question