• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Error when manipulating the date 2008-11-02

I'm coming across a very strange problem when  my script hits 2008-11-02 and I'm not sure why. What the script does is accept a start date and an end date and then loops through days between. It works perfectly as long as the date range doesn't include 2008-11-02. If it does, it will never get passed that date during the accumulation looping process. What am I missing? Any help would be most appreciated.
<?php
		$s = date("Y-m-d", strtotime($_POST['startDate']));
		$e = date("Y-m-d", strtotime($_POST['endDate']) + 86400);
		while($s != $e){
			$count++
    ?>
    	<th align="right"><?= date("Y-m-d", strtotime($s)); ?></th>
    <?php
			$time = strtotime($s) + 86400;
			
			$s = date("Y-m-d", $time);
			if($count > 200){
				die("This catch is in here for the 11/02/2008 bug.");
			}
		}
     ?>

Open in new window

0
brettfarris
Asked:
brettfarris
  • 2
1 Solution
 
spoxoxCommented:
Because Nov 2 the time changed.

You need to add another 3600 seconds to make up the shortfall for that day (only).
0
 
spoxoxCommented:
i.e.

      $time = strtotime($s) + 86400;
      if ($time == 1225684800) $time+= 3600; // might be a nicer way to do this!
0
 
brettfarrisAuthor Commented:
Excellent, that definitely sent me in the right direction. Thanks for your assistance. Here's how I handled it:
$time = strtotime($s) + 86400;
			
// The following block handles time change.
if((string)date("Y-m-d", $time) == (string)date("Y-m-d", strtotime($s))){
  $time += 3600;
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now