Vonder
Vonder

Reputation: 4059

How to read date from the form and calculate a timestamp

I would like to calculate a timestamp based on the input date. I would like to calculate it from the user input (something like 12/12/2011) I guess I need a function that changes the format to something readable for php and then calculate timestamp for this date. Maybe I should use strtotime() function? Any ideas will be appreciated.

  $date = $_POST['date'];

 <input type="text" name="date" value="">

Upvotes: 0

Views: 168

Answers (1)

DuoSRX
DuoSRX

Reputation: 4199

Indeed you can use strtotime:

if (($timestamp = strtotime($date)) === false) {
  echo "not good";
} else {
  echo $timestamp;
}

Check the php documentation.

Upvotes: 2

Related Questions