|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-27 10:14 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 16:00:02 2025 UTC |
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.