Jump to content

How can adjust this code to account for daylight savings time?


bschultz

Recommended Posts

<?php

if(date('w') == 0)
    $str = 'today';
else
    $str = 'last sunday';

$timestamp = strtotime($str);
//echo $timestamp;
echo "<img src='brn_masthead.gif' width='500' /><br /><table border='1'><tr>";
echo "<tr><td align='center' width='140'><b>Sunday</b></td><td align='center' width='140'><b>Monday</b></td><td align='center' width='140'><b>Tuesday</b></td><td align='center' width='140'><b>Wednesday</b></td>
<td align='center' width='140'><b>Thursday</b></td><td align='center' width='140'><b>Friday</b></td><td align='center' width='140'><b>Saturday</b></td></tr><tr>";

$j = 0;
for($i = 0; $i < 14; $i++)
{
$thisdate = date('Y-m-d', $timestamp + ($i * (60 * 60 * 24)));

?>

 

I've looked into mktime and checked the manual, but can't find anything that seems to work inside the loop.

 

Thanks!

Link to comment
Share on other sites

It's a two week calendar.  Everything worked up until this week.  The events for the 6th (Sunday - first day of daylight savings time) are showing up on the column for Sunday AND the column for Monday, and every other day's content is showing up one day late (in the calendar format).

Link to comment
Share on other sites

OK, after looking at the output I assume your issue is that you are getting 10-30 twice in the results. That is because you didn't specify an hour in your seed timestamp - so the start timestamp is set to midnight. Then, when you go forward 24 hours over the day where we "fall back" you are at 23:00 (11PM) of that same day. The solution is simple set your seed timestamp in the middle of the day.

 

$str = 'last sunday 12PM';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.