Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Last week date ranges in php , week Monday to sunday

Tags:

php

Using a Php date functions i would like to get the last week date ranges,

for example.

its Friday, 24th June 2016 Today.

I want the out put

Last week Start Date : 2016-06-13 (YYYY-mm-dd Format)

Last week End Date : 2016-06-19 (YYYY-mm-dd Format)

Is that possible ?

like image 647
Punit Gajjar Avatar asked Dec 18 '22 16:12

Punit Gajjar


2 Answers

<?php
 echo date("Y-m-d", strtotime("last week monday"));
 echo "<br>";
echo date("Y-m-d", strtotime("last sunday"));
?>
like image 114
Shibon Avatar answered Jan 14 '23 18:01

Shibon


Just use strtotime function:

echo date("Y-m-d",strtotime('sunday',strtotime('last week'))); //2016-06-19
echo date("Y-m-d",strtotime('monday',strtotime('last week'))); //2016-06-13
like image 25
Thamilhan Avatar answered Jan 14 '23 20:01

Thamilhan