-4

Which is correct way of converting datetime string in format like '2014-12-06 07:45' in timestamp ?
I make like

date( "Y-m-d H:i", '2014-12-06 07:45' );

but time is zero...

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
user2339232
  • 757
  • 3
  • 11
  • 22
  • please search this site repository before posting this kind of repeatative questions. – Vaisakh Pc Dec 05 '14 at 11:43
  • You get zero cause the second argument should be timestamp (integer), not a string. Please, check http://php.net/manual/en/function.date.php and try to view every relevant function on the right part of that page. – loshad vtapkah Dec 05 '14 at 11:47

2 Answers2

1

Flexible format way:

$date = \DateTime::createFromFormat('Y-m-d H:i', '2014-12-06 07:45');

echo $date->getTimestamp();
Leto
  • 2,594
  • 3
  • 24
  • 37
0

This should work for you:

echo strtotime("2014-12-06 07:45");

Output:

1417848300
Rizier123
  • 58,877
  • 16
  • 101
  • 156