FaRmBoX Posted November 14, 2009 Share Posted November 14, 2009 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 More sharing options...
Mchl Posted November 14, 2009 Share Posted November 14, 2009 if(time() > strtotime('2009-11-14 13:38') && time() < strtotime('2009-11-15 08:38')) { } strtotime can also accept different time formats. Link to comment https://forums.phpfreaks.com/topic/181548-current-datetime-in-between-2-datetimes/#findComment-957646 Share on other sites More sharing options...
FaRmBoX Posted November 14, 2009 Author Share Posted November 14, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181548-current-datetime-in-between-2-datetimes/#findComment-957658 Share on other sites More sharing options...
Mchl Posted November 15, 2009 Share Posted November 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181548-current-datetime-in-between-2-datetimes/#findComment-957884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.