Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6621395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:15:30+00:00 2026-05-25T21:15:30+00:00

I’m trying to get every X days from a given date for a calendar.

  • 0

I’m trying to get every X days from a given date for a calendar. I think I have the logic down to an extent, but for a small window of dates I am getting unexpected results.

My code below taken from my project:

$start_time = 1345935600; //Sept 25th 2011; 
$end_time = 1355011200; //Dec 9th 2011;

$sStartDate = date("Y-m-d", $start_time) . " " . date("H:i:s", strtotime("00:00:00"));
$sEndDate = date("Y-m-d", $end_time) . " " . date("H:i:s", strtotime("00:00:00"));
$sCurrentDate = $sStartDate; 

while($sCurrentDate < $sEndDate)
{                                       
    $t_date = strtotime($sCurrentDate);
    $s_date = strtotime(date("Y-m-d", strtotime("08/30/2011")));

    $recurs_every = 60 * 60 * 24 * 2; //occurs every 2 days

    echo date("Y-m-d H:i:s", $t_date) . " " . date("Y-m-d H:i:s", $s_date) . " " . (($t_date - $s_date) % $recurs_every) . " " . $recurs_every . "<BR>" ;   

    $sCurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));                                               
}

Outputs (current date – start date – modular) :

2011-09-25 00:00:00 2011-08-30 00:00:00 0
2011-09-26 00:00:00 2011-08-30 00:00:00 86400
....
2012-10-27 00:00:00 2011-08-30 00:00:00 0
2012-10-28 00:00:00 2011-08-30 00:00:00 86400
2012-10-29 00:00:00 2011-08-30 00:00:00 3600
2012-10-30 00:00:00 2011-08-30 00:00:00 90000
2012-10-31 00:00:00 2011-08-30 00:00:00 3600
2012-11-01 00:00:00 2011-08-30 00:00:00 90000
2012-11-02 00:00:00 2011-08-30 00:00:00 3600
2012-11-03 00:00:00 2011-08-30 00:00:00 90000
2012-11-04 00:00:00 2011-08-30 00:00:00 3600
2012-11-05 00:00:00 2011-08-30 00:00:00 90000

The last few lines are the issue for me.

3600 is one hour and I don’t know where this is coming from. Strange thing is, fast forward to march 26 2012 and it starts to work again but same error occurs at Oct 29 2012…

I’ve been at this for a few hours and can’t figure this out. Any help really appreciated!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:15:30+00:00Added an answer on May 25, 2026 at 9:15 pm

    In some contries there is a summer & winter time where the clock is converted one hour (@ 27 march & 30 oct). Therefore there is a one hour difference.

    -> http://en.wikipedia.org/wiki/Daylight_saving_time

    Example:

    <?
    
    error_reporting(E_ALL);
    
    $start_time = 1345935600; //Sept 25th 2011; 
    $end_time = 1355011200; //Dec 9th 2011;
    
    $sStartDate = date("Y-m-d", $start_time) . " " . date("H:i:s", strtotime("00:00:00"));
    $sEndDate = date("Y-m-d", $end_time) . " " . date("H:i:s", strtotime("00:00:00"));
    $sCurrentDate = $sStartDate; 
    
    $lastDate = 0;
    $corr = 0;
    
    while($sCurrentDate < $sEndDate)
    {                                       
        $t_date = strtotime($sCurrentDate);
        $s_date = strtotime(date("Y-m-d", strtotime("08/30/2011")));
    
        $recurs_every = 60 * 60 * 24 * 2; //occurs every 2 days
    
        echo date("Y-m-d H:i:s", $t_date) . " " . date("Y-m-d H:i:s", $s_date) . " " . (($t_date - $s_date + $corr) % $recurs_every) . " " . $recurs_every . "<BR>" ;   
    
        $lastDate = strtotime($sCurrentDate);
        $sCurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));             
    
        if(strtotime($sCurrentDate) - $lastDate != 60 * 60 * 24) {
            $corr -= strtotime($sCurrentDate) - $lastDate - 60 * 60 * 24;
        }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.