Reputation: 2662
I need to get the Unix time stamp of the last sunday at 8 pm, so I tried:
strtotime("last sunday 8 pm");
This works great, but if it is 22-11-2015
at 9 PM for instance, the output is 15-11-2015 8 PM
instead of one hour ago. The method above works great except during the last four hours of sunday. How can I get 22-11-2015 8 PM
?
Upvotes: 1
Views: 510
Reputation: 1253
Proper, but longer, way to complete this task
if((date('D',time()) == 'Sun') && (time() > strtotime('today 8 pm'))){ //if today is sunday and after 8pm, give todays date.
$unix = strtotime('today 8 pm');
}
else{ //not sunday today, return last sunday.
$unix = strtotime('last sunday');
}
Hacky/Original code: You could check for "last sunday 8 pm" from tomorrows date.
strtotime('last sunday 8 pm', strtotime('tomorrow'));
Upvotes: 1