I have tried various answers that I found in SO but still I can't manage to make a date into timestamp and I always get a wrong result.
I have tried:
$date = $this->loadTemplate('element'); //2014-02-27 15:03:00
list($year, $month, $day, $hour, $minute, $second) = split('[- :]', $date);
$timestamp = mktime((int) $hour, (int) $minute,(int) $second,(int) $month,(int) $day,(int) $year);
echo date("r", $timestamp);
And the result I'm getting is:
Wed, 02 Dec 2026 00:00:00 -0700
What am I doing wrong here?
EDIT
It turned out that the problem was a newline
that was generated by $date
. I stripped the string from newlines
and it worked like a charm.