jeeva Posted April 6, 2007 Share Posted April 6, 2007 hi frnds i have a form there user can select the time and date. the date and time should be more than current time the time format is like 9:30 pm. now how can i check this time is more than current time using php? Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/ Share on other sites More sharing options...
Lumio Posted April 6, 2007 Share Posted April 6, 2007 <?php $input = '9:30 am'; if (preg_match('{^[\d]{1,2}:[\d]{1,2} [apm]{2}$}', $input)) { echo 'ok'; }else { echo 'wrong'; } ?> Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222819 Share on other sites More sharing options...
jeeva Posted April 6, 2007 Author Share Posted April 6, 2007 i think u did not understand my qtn i am asking about the selected time should be more than current time. for that how do i compare with current time? not for the format Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222821 Share on other sites More sharing options...
Lumio Posted April 6, 2007 Share Posted April 6, 2007 You mean, you got a list with timeformats? Then use date() - http://php.net/date Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222826 Share on other sites More sharing options...
jeeva Posted April 6, 2007 Author Share Posted April 6, 2007 No i need to validate Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222830 Share on other sites More sharing options...
obsidian Posted April 6, 2007 Share Posted April 6, 2007 If the input is in 9:30 am format, just use strtotime() to compare with time() like this: <?php $time = "9:30 am"; $ts = strtotime($time); if ($ts > time()) { // it's later than NOW } else { // it's not later than NOW } ?> Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222832 Share on other sites More sharing options...
Lumio Posted April 6, 2007 Share Posted April 6, 2007 Ah... sorry for my missundertanding Link to comment https://forums.phpfreaks.com/topic/45867-date-and-time-validate/#findComment-222863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.