Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need to check if time now is between two times

I need to check IF time is between two times with PHP I tried a lot of examples but they are not working for me, I guess I’m asking a stupid question but I’m not finding any answer.

$datetime1 = new DateTime('03:55:06');//start time
$datetime2 = new DateTime('11:55:06');//end time

I need to check IF current time is between $datetime1 and $datetime2.

IF is between { do something } ELSE { do somehting }.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :


$start = new DateTime("11:59:59");
$end = new DateTime("13:59:59");
$now = new DateTime();

if($now < $end and $now > $start)
{
    echo "Yes, now is between start and end";
}
else 
{
  // do something else
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading