php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43113 Date problem -
Submitted: 2007-10-27 00:00 UTC Modified: 2007-10-27 10:14 UTC
From: anderson at berkeleypim dot com dot br Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.4 OS: linux
Private report: No CVE-ID: None
 [2007-10-27 00:00 UTC] anderson at berkeleypim dot com dot br
Description:
------------
Problem in ADD day a date

Reproduce code:
---------------
<? $data_inicio = '2007-10-23'; $data_fim='2007-11-08';$data_fim1='2007-10-23'; $i=0;
	while ($data_fim1 <= $data_fim)
		{  	$i=$i+1; 				$data_fim1 			= soma_dia($data_inicio,$i);
			echo "<br>".$data_inicio." d=".$data_fim1." i=".$i;
		}
function soma_dia($this_date,$num_days){
   $my_time 		= strtotime ($this_date); //converts date string to UNIX timestamp
   $timestamp 		= $my_time + ($num_days * 86400); //calculates # of days passed ($num_days) * # seconds in a day (86400)
     $return_date 	= date("Y-m-d",$timestamp);  //puts the UNIX timestamp back into string format
   return $return_date;//exit function and return string 
}
?>


Expected result:
----------------
2007-10-23 d=2007-10-24 i=1
2007-10-23 d=2007-10-25 i=2
2007-10-23 d=2007-10-26 i=3
2007-10-23 d=2007-10-27 i=4
2007-10-23 d=2007-10-28 i=5
2007-10-23 d=2007-10-29 i=6
2007-10-23 d=2007-10-30 i=7
2007-10-23 d=2007-10-31 i=8
2007-10-23 d=2007-11-01 i=9
2007-10-23 d=2007-11-02 i=10
2007-10-23 d=2007-11-03 i=11
2007-10-23 d=2007-11-04 i=12         ***************************
2007-10-23 d=2007-11-05 i=13         ****** SAME - IS IMPOSSIBLE) 
2007-10-23 d=2007-11-06 i=14
2007-10-23 d=2007-11-07 i=15
2007-10-23 d=2007-11-08 i=16
2007-10-23 d=2007-11-09 i=17
2007-10-23 d=2007-11-10 i=18

OK - runing at HOSTGATOR.COM at 21:37 brazil timezone. 

Actual result:
--------------
2007-10-23 d=2007-10-24 i=1
2007-10-23 d=2007-10-25 i=2
2007-10-23 d=2007-10-26 i=3
2007-10-23 d=2007-10-27 i=4
2007-10-23 d=2007-10-28 i=5
2007-10-23 d=2007-10-29 i=6
2007-10-23 d=2007-10-30 i=7
2007-10-23 d=2007-10-31 i=8
2007-10-23 d=2007-11-01 i=9
2007-10-23 d=2007-11-02 i=10
2007-10-23 d=2007-11-03 i=11
2007-10-23 d=2007-11-04 i=12         ***************************
2007-10-23 d=2007-11-04 i=13   ** SAME - IS IMPOSSIBLE) Look a date
2007-10-23 d=2007-11-05 i=14
2007-10-23 d=2007-11-06 i=15
2007-10-23 d=2007-11-07 i=16
2007-10-23 d=2007-11-08 i=17
2007-10-23 d=2007-11-09 i=18

OK - runing at HOSTGATOR.COM at 21:37 brazil timezone. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-27 10:14 UTC] derick@php.net
We are happy to tell you that you just discovered Daylight Savings
Time. For more information see:
http://webexhibits.org/daylightsaving/b.html
Instead of using mktime/date consider using gmmktime and gmdate which do
not suffer from DST.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 02:01:33 2024 UTC