Here is what I have so far:
$date = date('Y-m-d h:i:s', strtotime('-7 days'));
$start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday'));
When outputting $start, it returns: 1969-12-31 06:00:00
What am I doing wrong?
Here is what I have so far:
$date = date('Y-m-d h:i:s', strtotime('-7 days'));
$start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday'));
When outputting $start, it returns: 1969-12-31 06:00:00
What am I doing wrong?
$date
needs to e a timestamp
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date));
You have the arguments the wrong way round:
date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
Edit: Furthermore, you have made $date
a formatted string. It needs to be a timestamp, so your code should look something like this:
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
Per php doc
date('Y-m-d h:i:s', strtotime('last Sunday', $date));
If your date is not a timestamp you can still use strtotime
, like suppose your date was passed in already and is in a string format of another kind.
$date = '2013-11-10';
$lastsunday = date('Y-m-d',strtotime($date.' last Sunday'));
This can save a bit of time trying to get your date into a format that "works"