droidus Posted August 27, 2012 Share Posted August 27, 2012 I am trying to format my date that I retrieve from a database. here is my code: $date = 1346078003; echo $date->format('Y-m-d H:i:s'); Quote Link to comment https://forums.phpfreaks.com/topic/267652-formatting-date-from-numbers/ Share on other sites More sharing options...
Jessica Posted August 27, 2012 Share Posted August 27, 2012 You need to turn on error_reporting and set it to E_ALL. The code you have will generate plenty of errors. If you got them, you should post them with your code for the future. You have an integer and are trying to use it as an object. The proper syntax for this would be echo date('Y-m-d H:i:s', $date); If you are trying to use a DateTime object, you need to create that object, rather than trying to use the int you have. Quote Link to comment https://forums.phpfreaks.com/topic/267652-formatting-date-from-numbers/#findComment-1372879 Share on other sites More sharing options...
scootstah Posted August 27, 2012 Share Posted August 27, 2012 You forgot the DateTime constructor. $date = 1346078003; should be $date = new DateTime(1346078003); The manual would have told you this. http://us2.php.net/datetime Quote Link to comment https://forums.phpfreaks.com/topic/267652-formatting-date-from-numbers/#findComment-1372894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.