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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 + 48 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Mar 28 11:01:27 2024 UTC