Skip to content

Instantly share code, notes, and snippets.

@gharabaghi
Created February 2, 2021 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gharabaghi/9160b6da511001ff1ceecb049223baf5 to your computer and use it in GitHub Desktop.
Save gharabaghi/9160b6da511001ff1ceecb049223baf5 to your computer and use it in GitHub Desktop.
php check if hour and minute in form of H:i is before now
public static function isHourBeforeNow($hour)
{
$now = date('H:i');
$nowArray = explode(':', $now);
$hourArray = explode(':', $hour);
if ($nowArray[ 0 ] < $hourArray[ 0 ]) {
return false;
} else if ($nowArray[ 0 ] > $hourArray[ 0 ]) {
return true;
} else {
if ($nowArray[ 1 ] < $hourArray[ 1 ]) {
return false;
} else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment