note 83759 modified in function.strtotime by felipe

From: Date: Tue, 10 Jun 2008 17:10:39 +0000
Subject: note 83759 modified in function.strtotime by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140316@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. --was-- 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. http://php.net/manual/en/function.strtotime.php

« previous php.notes (#140316) next »