if send day , time (not date) datetime api :
$tz = new \datetimezone("utc"); $now = new \datetime("now", $tz); $then = \datetime::createfromformat('l g a', 'thursday 8 pm', $tz);
and saturday 26th march, $then, when echoed follows :
echo $then->format('l js, f');
will return :
thursday 31st, march
how make return date of thursday in current week has passed :
thursday 24th march
not next thursday?
datetime::__construct()
, strtotime()
uses a lot of rules guess mean when specify incomplete or relative date. of times thy guess right of rules similar , final result not 1 expected programmer.
datetime::createfromformat()
limited, cannot understand formats list.
you try parse relative date format. when day name specified, interpreted next occurrence of specified day of week (see dayname entry under day-based notations table in documentation.)
you can date want using thursday week instead. datetime::createfromformat()
doesn't understand relative dates contain references week datetime::__construct()
does.
try this:
$then = new \datetime('thursday week 8 pm', $tz);
Comments
Post a Comment