1

It is worth mentioning I'm using PHP 5.2 so can't use the DateTime class.

I have the following code:

$date_begin = mysql_real_escape_string($_POST['dateBegin']);
$date_end   = mysql_real_escape_string($_POST['dateEnd']);

Imagine they are now

$date_begin = "28/02/2015";
$date_end   = "22:00:00";

How can I convert this into a php/unix timestamp?

Thanks

  • possible duplicate of [How to convert UNIX timestamp to DateTime and vice versa?](http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa) –  Feb 17 '15 at 03:57
  • No, it's not. Don't jump the gun please –  Feb 17 '15 at 03:59
  • This answer any help? http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php –  Feb 17 '15 at 04:09

1 Answers1

0

If you flip the month and day values you can use strtotime.

$date_begin = preg_replace('~(\d+)/(\d+)/(\d+)~', "$2/$1/$3", "28/02/2015");
$date_end   = "22:00:00";
echo strtotime($date_begin . ' ' . $date_end);
chris85
  • 23,846
  • 7
  • 34
  • 51