|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40171 There should be a way to create DateTime object from UTC timestamp.
Submitted: 2007-01-19 16:27 UTC Modified: 2007-01-19 18:25 UTC
Avg. Score:3.4 ± 1.1
Reproduced:47 of 55 (85.5%)
Same Version:25 (53.2%)
Same OS:19 (40.4%)
From: rkumar at msgme dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-01-19 16:27 UTC] rkumar at msgme dot com
The constructor for DateTime object currently takes a string 
as a parameter. In most of the scenarios that I have encountered I need to create a DateTime object from UTC timestamp. Can the constructor  be changed to accept string or integer? 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-19 18:25 UTC]
That would be too confusing, as PHP auto casts and "20070119" is something quite different from the unix timestamp 20070119. What you can do is pass this to the ctor: "@20070119" - the @ makes it interpret as a Unix timestamp.
 [2020-07-08 02:32 UTC] vin526vin at gmail dot com
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
        die("<br><strong>This script is only meant to run at the command line.</strong>");

$args = getopt("v:c:h:");
$strResult = exec( "/bin/snmpwalk -v ".$args['v']." -c ".$args['c']." ".$args['h']." .");
$aryDate = explode("," , str_replace('STRING: ', '', substr($strResult, strpos($strResult, 'STRING'))));
$strDate = $aryDate[0].' '.substr($aryDate[1], 0, -2);

$d1 = new DateTime($strDate);
$d2 = new DateTime(date("Y-m-d H:i:s"));
$totalDiff = $diff->format("%d")*86400+$diff->format("%h")*3600+$diff->format("%i")*60+$diff->format("%s");

echo "TimeDiff:".$totalDiff."\n";
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Jun 06 10:03:37 2023 UTC