PHP getting work day range of a week

69

I'm trying to get work day range of a week, here is the code I have:

$from_ = date("Y-m-d", mktime(0, 0, 0, date("m")-3, 1, date("Y")));
$to_ = date("Y-m-d", mktime(0, 0, 0, date("m")-2, 0, date("Y")));
echo $from_ . ' - ' . $to_;

gives me days between 'May': 2015-05-01 - 2015-05-31

$week_start = date('m-d-Y', strtotime('-'.date('w').' days'));
$week_end = date('m-d-Y', strtotime('+'.(5-date('w')).' days'));
echo $week_start . ' - ' . $week_end;

gives me current months first weeks work day range: 08-02-2015 - 08-07-2015

My questions is: How do I combine these two? for example; I need 'May's second weeks work day range which is this result: 2015-05-04 - 2015-05-08

271

Answer

Solution:

You can use more English-y phrases with strtotime. Try this:

$second_week_start = strtotime('1st may 2015 next monday'); // gets the date of the first monday after the given date (e.g. the start of the second week)

$second_week_end = strtotime('next friday', $second_week_start); // the friday after the previous date

echo date('Y-m-d', $second_week_start) . ' - ' . date('Y-m-d', $second_week_end);

People are also looking for solutions to the problem: javascript - google map markers php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.