I want to do something like this:
If current time is > 19:30 and < 10:00 print yesterday's date [e.g. Thursday October 17th]
Else print today's date [e.g. Friday October 18th].
How can this be done with PHP?
I want to do something like this:
If current time is > 19:30 and < 10:00 print yesterday's date [e.g. Thursday October 17th]
Else print today's date [e.g. Friday October 18th].
How can this be done with PHP?
You can use createFromFormat()
method to convert your time string into a DateTime
object and do the comparison, like so:
$now = new DateTime('now');
$time1 = DateTime::createFromFormat('H:i', '19:30');
$time2 = DateTime::createFromFormat('H:i', '10:00');
if ($now > $time1 && $now < $time2) {
echo $now->format('l F dS');
} else {
$now->modify('-1 day');
echo $now->format('l F dS');
}