note 114093 added to class.datetime

From: Date: Fri, 10 Jan 2014 14:05:00 +0000
Subject: note 114093 added to class.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-198191@lists.php.net to get a copy of this message
This caused some confusion with a blog I was working on and just wanted to make other people aware of this. If you use createFromFormat to turn a date into a timestamp it will include the current time. For example: <?php $publishDate = DateTime::createFromFormat('m/d/Y', '1/10/2014'); echo $publishDate->getTimestamp(); ?> Would not output the expected "1389312000" instead it would output something more like "1389344025". To fix this you would want to do: <?php $publishDate = DateTime::createFromFormat('m/d/Y', '1/10/2014'); $publishDate->setTime(0, 0, 0); echo $publishDate->getTimestamp(); ?> I hope this helps someone! ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/class.datetime.php Edit -- https://master.php.net/note/edit/114093 Del: integrated -- https://master.php.net/note/delete/114093/integrated Del: useless -- https://master.php.net/note/delete/114093/useless Del: bad code -- https://master.php.net/note/delete/114093/bad+code Del: spam -- https://master.php.net/note/delete/114093/spam Del: non-english -- https://master.php.net/note/delete/114093/non-english Del: in docs -- https://master.php.net/note/delete/114093/in+docs Del: other reasons-- https://master.php.net/note/delete/114093 Reject -- https://master.php.net/note/reject/114093 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198191) next »