php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69150 DateTime object does not update micro seconds
Submitted: 2015-02-28 23:47 UTC Modified: 2015-03-02 18:46 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: remyfox at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.6 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: remyfox at hotmail dot com
New email:
PHP Version: OS:

 

 [2015-02-28 23:47 UTC] remyfox at hotmail dot com
Description:
------------
Micro seconds on the date property (and consequently, formatted output) do not update after the initial creation of the DateTime object.

Test script:
---------------
$datetime = Datetime::createFromFormat('Y-m-d H:i:s.u', '2009-02-09 15:16:17.015750');
$datetime->setTimeStamp(0);
print_r($datetime);
	
$datetime = Datetime::createFromFormat('Y-m-d H:i:s', '2009-02-09 15:16:17');
$datetime->setTimeStamp(0.123);
print_r($datetime);

Expected result:
----------------
DateTime Object
(
    [date] => 1970-01-01 01:00:00.000000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)
DateTime Object
(
    [date] => 1970-01-01 01:00:00.123000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

Actual result:
--------------
DateTime Object
(
    [date] => 1970-01-01 01:00:00.015750
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)
DateTime Object
(
    [date] => 1970-01-01 01:00:00.000000
    [timezone_type] => 3
    [timezone] => Europe/Berlin
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-02 00:09 UTC] cmbecker69 at gmx dot de
This is not a bug.

It is documented that DateTime::setTimestamp()[1] expects a Unix
timestamp as int argument.  Any float passed to this method is
casted to integer.

[1] <http://php.net/manual/en/datetime.settimestamp.php>
 [2015-03-02 18:46 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2015-03-02 18:46 UTC] aharvey@php.net
Yep: any date/time function that deals with UNIX timestamps is limited to second precision by definition, since PHP always treats them as integers.

Closing not a bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 05:00:01 2026 UTC