Punit Gajjar
Punit Gajjar

Reputation: 4987

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

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 ?

Upvotes: 4

Views: 7087

Answers (4)

Shibon
Shibon

Reputation: 1574

<?php
 echo date("Y-m-d", strtotime("last week monday"));
 echo "<br>";
echo date("Y-m-d", strtotime("last sunday"));
?>

Upvotes: 8

Jayesh Chitroda
Jayesh Chitroda

Reputation: 5049

Try:

$start_week = strtotime("last monday midnight");
$end_week = strtotime("+1 week",$start_week);

$start_week = date("Y/m/d",$start_week);
$end_week = date("Y/m/d",$end_week);

echo $start_week.' '.$end_week ;

Upvotes: 0

ixe
ixe

Reputation: 89

Yes, it is possible. Use strtotime()
Date formats

strtotime('sunday', 'Fri June 24th, 2016"')
strtotime('monday', 'Fri June 24th, 2016"')

Upvotes: 0

Thamilhan
Thamilhan

Reputation: 13313

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

Upvotes: 3

Related Questions