It should be
DateTime::createFromFormat('Y/m/d H:i:s','2010/08/09 07:47:00')->getTimestamp()
^ ^
See date
for the format used.
You could also use strtotime
in this circumstance. This would give the same result:
strtotime('2010/08/09 07:47:00')
Another way:
date_create('2010/08/09 07:47:00')->getTimestamp()
Note that DateTime::createFromFormat
returns FALSE
on error. You can fetch the errors with DateTime::getLastErrors()
:
<?php
$d = DateTime::createFromFormat('Y/m/d H:M:S','2010/08/09 07:47:00');
var_dump($d);
var_dump(DateTime::getLastErrors());
would give:
bool(false)
array(4) {
["warning_count"]=>
int(0)
["warnings"]=>
array(0) {
}
["error_count"]=>
int(3)
["errors"]=>
array(1) {
[14]=>
string(13) "Trailing data"
}
}