Patrioticcow
Patrioticcow

Reputation: 27038

php, how not to let a user enter a past date?

i have a form 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

Upvotes: 0

Views: 107

Answers (3)

Kumar
Kumar

Reputation: 5147

  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

Upvotes: 0

No Results Found
No Results Found

Reputation: 102745

if (strtotime($_POST['date_ts']) < time()) // Past date was posted

Upvotes: 1

Chris Warrick
Chris Warrick

Reputation: 1629

You can convert the date to an Unix timestamp (strtotime() and compare it with time(); (note: will not work with today)

Upvotes: 2

Related Questions