开发者

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


  1. Use JS to check if the date entered is less than today's date. Problem nailed at first step. If not goto step 2
  2. strtomtime() is wonderful, use this date("m-d-Y", strtotime('now')) to get in dd-mm-yyyy format or any other suitable for your comparison, look at http://php.net/date for more date() formatting options
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜