php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27655 Strtotime incorrectly recognises certain MySQL timestamps
Submitted: 2004-03-19 06:32 UTC Modified: 2005-09-25 12:58 UTC
Votes:5
Avg. Score:3.4 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:0 (0.0%)
From: richardNO at SPAMPLEASEthe-moon dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.4 OS: Windows XP
Private report: No CVE-ID: None
 [2004-03-19 06:32 UTC] richardNO at SPAMPLEASEthe-moon dot net
Description:
------------
Usually strtotime doesn't recognise MySQL timestamps and returns -1. I noticed though that for some hours of 2004-03-18 it suddenly started returning a timestamp. I've created some code to illustrate. I only came across this because it affects the Smarty date modifier.

-RichardW.

Reproduce code:
---------------
<?php
	/**
	 * Generates MySQL timestamps over 48 hours from 2004-03-18
	 * Displays results of PHP strtotime on MySql timestamps over that period
	 **/
	for( $i=1; $i<=48; $i++ )
	{
		$unixTimeStamp = mktime($i,0,0,3,18,2004);
		$mysqlTimeStamp = strftime('%Y%m%d%H%M%S', $unixTimeStamp);
		$strToTimeStamp = strtotime($mysqlTimeStamp);
		$displayDate = '?';
		
		if ($strToTimeStamp != -1)
		{
			$displayDate = strftime('%Y-%m-%d (%H:%M:%S)', $strToTimeStamp);
		}
		
		printf('<p>%s = %s = %s</p>', $mysqlTimeStamp, $strToTimeStamp, $displayDate);
	}	
?>

Expected result:
----------------
20040318010000 = -1 = ?

20040318020000 = -1 = ?

20040318030000 = -1 = ?

20040318040000 = -1 = ?

20040318050000 = -1 = ?

20040318060000 = -1 = ?

20040318070000 = -1 = ?

20040318080000 = -1 = ?

20040318090000 = -1 = ?

20040318100000 = 149986800 = 1974-10-03 (00:00:00)

20040318110000 = 181522800 = 1975-10-03 (00:00:00)

20040318120000 = 213145200 = 1976-10-03 (00:00:00)

20040318130000 = 244681200 = 1977-10-03 (00:00:00)

20040318140000 = 276217200 = 1978-10-03 (00:00:00)

20040318150000 = 307753200 = 1979-10-03 (00:00:00)

20040318160000 = 339375600 = 1980-10-03 (00:00:00)

20040318170000 = 370911600 = 1981-10-03 (00:00:00)

20040318180000 = 402447600 = 1982-10-03 (00:00:00)

20040318190000 = 433983600 = 1983-10-03 (00:00:00)

20040318200000 = 465606000 = 1984-10-03 (00:00:00)

20040318210000 = 497142000 = 1985-10-03 (00:00:00)

20040318220000 = 528678000 = 1986-10-03 (00:00:00)

20040318230000 = 560214000 = 1987-10-03 (00:00:00)

20040319000000 = -1 = ?

20040319010000 = -1 = ?

20040319020000 = -1 = ?

20040319030000 = -1 = ?

20040319040000 = -1 = ?

20040319050000 = -1 = ?

20040319060000 = -1 = ?

20040319070000 = -1 = ?

20040319080000 = -1 = ?

20040319090000 = -1 = ?

20040319100000 = -1 = ?

20040319110000 = -1 = ?

20040319120000 = -1 = ?

20040319130000 = -1 = ?

20040319140000 = -1 = ?

20040319150000 = -1 = ?

20040319160000 = -1 = ?

20040319170000 = -1 = ?

20040319180000 = -1 = ?

20040319190000 = -1 = ?

20040319200000 = -1 = ?

20040319210000 = -1 = ?

20040319220000 = -1 = ?

20040319230000 = -1 = ?

20040320000000 = -1 = ?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-25 12:58 UTC] nlopess@php.net
14-chars mysql timestamps work since PHP 5.1.0 (but not 12-chars timestamps).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC