The date string you pass is not supported by the DateTime parser. You must create a DateTime object using createFromFormat . This method allows you to specify a custom format when creating a new DateTime object:
$my_dt = DateTime::createFromFormat('mdY H:i:s', $token_created_at);
If you still get the error, it means that your $token_created_at not specified in the format you specified:
$now = date('mdY H:i:s'); //string(19) "06-28-2014 15:00:47" var_dump(DateTime::createFromFormat('mdY H:i:s', $now)); object(DateTime)
edit
I see your problem - the format string has a space after s . Format strings must match exactly :
$my_dt = DateTime::createFromFormat('mdY H:i:s ', $token_created_at);
Christian p
source share