Glynn Glynn - 1 year ago 47
PHP Question

php greater than certain time

I am trying to make a simple function to output 2 different lines of text depending on the time of the day. I want it to say after 4pm - Next day delivery will be processed the following day.

I have wrote this so far:


$currentTime = time() + 3600;
echo date('H:i',$currentTime);


However as the date function returns a string, I am unsure of how to use an IF statement to check whether the time is greater than 16:00

Thank you


Answer Source

Should do it

if (((int) date('H', $currentTime)) >= 16) {
  // .. do something

Because PHP is weak-typed you can omit the (int)-casting.

As a sidenote: If you name a variable $currentTime, you shouldn't add 1 hour to it, because then its not the current time anymore, but a time one hour in the future ;) At all

if (date('H') >= 16) { /* .. */ }