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? Quote Link to comment 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'; } ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
jeeva Posted April 6, 2007 Author Share Posted April 6, 2007 No i need to validate Quote Link to comment 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 } ?> Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 6, 2007 Share Posted April 6, 2007 Ah... sorry for my missundertanding Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.