note 83759 deleted from function.strtotime by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 08:02:06 +0000 |
| Subject: | note 83759 deleted from function.strtotime by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196747@lists.php.net to get a copy of this message | ||
Note Submitter: timstamp.co.uk
----
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.