Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get previous and next monday date by given date

Tags:

php

How we can get previous week monday date and next week monday date by provided date.Eample: if $date = '2015-04-08' (y-m-d format). then function returns, previous monday date = 2015-03-30 and next monday date = 2015-04-13

like image 519
phpboy Avatar asked Nov 27 '22 10:11

phpboy


2 Answers

echo "Next Monday:". date('Y-m-d', strtotime('next monday', strtotime($givenDate)));
echo "Previous Monday:". date('Y-m-d', strtotime('previous monday', strtotime($givenDate)));
like image 140
Sanjay Kumar N S Avatar answered Dec 09 '22 02:12

Sanjay Kumar N S


you can use

date('Y-m-d', strtotime('last week Monday'));
date('Y-m-d', strtotime('next week Monday'));

or whatever you want http://php.net/manual/en/datetime.formats.relative.php

like image 24
Asgu Avatar answered Dec 09 '22 01:12

Asgu