I need to get the timestamp for the current week's Wednesday and Saturday at 22:59, and then convert the timestamp to a human-readable date.
I've tried the following:
date_default_timezone_set('America/New_York');
$wednesdayLimit = strtotime('wednesday this week');
$saturdayLimit = strtotime('saturday this week');
$wednesdayLimit->setTime(22,59,0);
$saturdayLimit->setTime(22,59,0);
echo date("Y-m-d H:i:d", $wednesdayLimit);
echo date("Y-m-d H:i:d", $saturdayLimit);
But I get the following error:
Uncaught Error: Call to a member function setTime() on integer
One liner:
print date('Y-m-d H:i:s', strtotime('wednesday this week 22:59:00'));¸
Yields: 2016-01-27 22:59:00
How about
$wednesday = strtotime('wednesday this week');
$wednesdayStart = $wednesday - ($wednesday % 60*60*24);
$wednesdayEnd = $wednesdayStart + (60 * 60 * 24) - 1;
You could use DateTime and do something like this.
$date = new \DateTime();
$date->setISODate((int)$date->format('o'), (int)$date->format('W'), 3);
$date->setTime(22, 59, 0);
echo $date->format('D d-m-Y H:i:s');
Demo.
Or, if you like one liners.
$date = (new \DateTime())->modify('wednesday this week')->setTime(22, 59, 0);