Jump to content

Current Datetime in between 2 datetimes


FaRmBoX

Recommended Posts

What code can I use to determine when the current datetime is in between 2 datetimes.

 

This is what I came up with:

if ((date(m.d.y h:i a) > 11-14-09 01:38 pm) && (date(m.d.y h:i a) < 11-15-09 08:38 am)) {

  echo "It is time to do it!";

} else {

  echo "Its not ready yet.";

}

 

I hope you understand what im trying to do. However, my code doesnt look right to me in the sense of how I am comparing the dates. Help please.

 

Link to comment
https://forums.phpfreaks.com/topic/181548-current-datetime-in-between-2-datetimes/
Share on other sites

How do I convert from 11-15-09 01:38 pm format to 2009-11-15 13:38 format so I can use it with strtotime and compare the dates?

 

The date in the first format that I receive always changes, so I will need a way to convert it. Thanks for your help.

strtotime will parse '15-11-2009 01:38 pm' date, so it's just a matter of switching your month and day and adding 20 for the year.

 

$date = "11-15-09 01:38 pm";
echo $dateNew = substr($date,3,3).substr($date,0,3).'20'.substr($date,6);

 

This assumes that all your dates are from 21st century though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.