php, how not to let a user enter a past date?
i have a 开发者_如何学Cform and a input where i can place a date in this format m/d/y
<input type="text" name="date_ts" size=8 maxlength=8 value="">
i need to figure out a way of not letting the user input a date that is in the past.
any ideas? thanks
You can convert the date to an Unix timestamp (strtotime()
and compare it with time();
(note: will not work with today)
if (strtotime($_POST['date_ts']) < time()) // Past date was posted
- Use JS to check if the date entered is less than today's date. Problem nailed at first step. If not goto step 2
strtomtime()
is wonderful, use thisdate("m-d-Y", strtotime('now'))
to get indd-mm-yyyy
format or any other suitable for your comparison, look at http://php.net/date for moredate()
formatting options
精彩评论