php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52577 Incorrect date returning
Submitted: 2010-08-10 18:23 UTC Modified: 2010-08-30 17:41 UTC
From: vadimx at gmail dot com Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.3.3 OS: Windows
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: vadimx at gmail dot com
New email:
PHP Version: OS:

 

 [2010-08-10 18:23 UTC] vadimx at gmail dot com
Description:
------------
When i use unixtime in DateTime object, this returning wrong date, -1 day.

Test script:
---------------
$date = '7.8.2010';
echo "String: ".$date."<br>";
$date_format = 'j.m.Y';
$unixtime = strtotime($date);
echo "Unixtime: ".$unixtime."<br>";
echo "Date(PHP): ".date($date_format,$unixtime)."<br>";
$date = new DateTime('@'.$unixtime);
echo "DateTime(PHP Class): ".$date->format($date_format);

Expected result:
----------------
String: 7.8.2010
Unixtime: 1281128400
Date(PHP): 7.08.2010
DateTime(PHP Class): 7.08.2010

Actual result:
--------------
String: 7.8.2010
Unixtime: 1281128400
Date(PHP): 7.08.2010
DateTime(PHP Class): 6.08.2010

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-11 00:44 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2010-08-11 00:44 UTC] felipe@php.net
What timezone are you using?
 [2010-08-11 00:57 UTC] vadimx at gmail dot com
date_default_timezone_set('Europe/Kiev');
But, i try change timezone, but this no effect.
 [2010-08-11 01:08 UTC] felipe@php.net
For example, using date_default_timezone_set('UTC'); I cannot reproduce it.
But using your timezone I got same result.
 [2010-08-11 09:50 UTC] vadimx at gmail dot com
When i use date_default_timezone_set('UTC'), all ok. But in doc "Note: The 
$timezone parameter and the current timezone are ignored when the $time parameter 
either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-
01-28T15:00:00+02:00).". why timezone affect to unixtime?
 [2010-08-30 17:40 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=302889
Log: - Test for (non-)bug #52577.
 [2010-08-30 17:41 UTC] derick@php.net
-Status: Assigned +Status: Bogus
 [2010-08-30 17:41 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Because Unix time is always measure in seconds since 1970-01-01 00:00 *GMT*.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC