etrader Posted September 1, 2011 Share Posted September 1, 2011 How to write an IF condition for a specific time of day? e.g. between 18 and 18:30. To do something if the current time is between 18 and 18:30. Link to comment https://forums.phpfreaks.com/topic/246168-how-to-write-an-if-statement-for-a-period-of-time/ Share on other sites More sharing options...
joel24 Posted September 1, 2011 Share Posted September 1, 2011 use unix times (seconds passed since 1st Jan 1970) and then just work with numbers, the strtotime() function is very useful... i.e. //current time $time = time(); $min = strtotime("6:00pm"); $max strtotime("6:30pm"); if ($time >= $min && $time <= $max) { echo 'time is between'; } else { echo 'not between'; } Link to comment https://forums.phpfreaks.com/topic/246168-how-to-write-an-if-statement-for-a-period-of-time/#findComment-1264206 Share on other sites More sharing options...
etrader Posted September 1, 2011 Author Share Posted September 1, 2011 Thanks a million Link to comment https://forums.phpfreaks.com/topic/246168-how-to-write-an-if-statement-for-a-period-of-time/#findComment-1264209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.