note 83759 added to function.strtotime

From: Date: Tue, 10 Jun 2008 15:31:13 +0000
Subject: note 83759 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-140310@lists.php.net to get a copy of this message
When using DB2 as an ODBC database source, the timestamps returned are in format "YYYY-MM-DD HH:MM:SS.mmmmmm" (m being microseconds). Given that strtotime($str) is only accurate down to the second, you need to remove the microseconds from the string for it to work in strtotime. For example: <?php $date = "2008-06-10 16:15:50.123456"; //as returned by DB2 SQL $date = substr($date, 0, 19); //chop off the last 7 characters //thus $date == 1213110950; //and date('Y-m-d H-i-s", $date) == "2008-06-10 16:15:50"; ?> Note that if you wish to preserve the microseconds, you will need to do so before you chop them off of the string, but you don't need to include them or even pad timestamps with zeros when inserting them back into DB2. ---- Server IP: 87.124.64.96 Probable Submitter: 195.212.29.83 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/83759 Del: integrated -- https://master.php.net/note/delete/83759/integrated Del: useless -- https://master.php.net/note/delete/83759/useless Del: bad code -- https://master.php.net/note/delete/83759/bad+code Del: spam -- https://master.php.net/note/delete/83759/spam Del: non-english -- https://master.php.net/note/delete/83759/non-english Del: in docs -- https://master.php.net/note/delete/83759/in+docs Del: other reasons-- https://master.php.net/note/delete/83759 Reject -- https://master.php.net/note/reject/83759 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140310) next »