php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43858 Bug in date generation with mktime and strtotime
Submitted: 2008-01-15 20:01 UTC Modified: 2008-01-15 20:03 UTC
From: nicollasrs at gmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.2.5 OS: Windows XP Professional SP2
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: nicollasrs at gmail dot com
New email:
PHP Version: OS:

 

 [2008-01-15 20:01 UTC] nicollasrs at gmail dot com
Description:
------------
When i try convert date "Jan 15 2008, 19:28:09 CET" to unix timestamp and convert again to date, php show incorrect date.

Reproduce code:
---------------
$Temp = "Jan 15 2008, 19:28:09 CET";
echo "Date: $Temp<br><br>";
echo "Trying strtotime: ".strtotime($Temp)."<br>";
echo "Date: ".date("d/m/Y - H:m:s", strtotime($Temp))."<br><br>";

function fixTime($Date) {
	$Date = str_replace(",", null, $Date);
	$Date = explode(" ", $Date);
	$DateTemp = strtotime($Date[0].$Date[1].$Date[2]);
	$Dia = date("d", $DateTemp); $Mes = date("m", $DateTemp); $Ano = date("Y", $DateTemp);
	$Time = explode(":", $Date[3]);
	$Hora = $Time[0]; $Minuto = $Time[1]; $Segundo = $Time[2];
	$CEST = $Date[4];
	echo "mktime($Hora, $Minuto, $Segundo, $Mes, $Dia, $Ano)<br><br>";
	return mktime($Hora, $Minuto, $Segundo, $Mes, $Dia, $Ano);
}

$Temp = fixTime($Temp);
echo "Trying mktime: $Temp<br>";
echo "Date: ".date("d/m/Y - H:m:s", $Temp)."<br>";

Expected result:
----------------
Date: Jan 15 2008, 19:28:09 CET

Trying strtotime: ??????????
Date: 15/01/2008 - 19:28:09

mktime(19, 28, 09, 01, 15, 2008)

Trying mktime: ?????????
Date: 15/01/2008 - 19:28:09

Actual result:
--------------
Date: Jan 15 2008, 19:28:09 CET

Trying strtotime: 1200421689
Date: 15/01/2008 - 16:01:09

mktime(19, 28, 09, 01, 15, 2008)

Trying mktime: 1200432489
Date: 15/01/2008 - 19:01:09

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-15 20:03 UTC] nicollasrs at gmail dot com
sorry... my bad
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC