Jump to content

Two leap years in five year period


JonathanS

Recommended Posts

Hope someone can help me. User defines two dates(dd/mm/yy, then want to display 1) Difference in days between the two inputs in dd/mm/yy and 2) the difference in days between the dates. The problem is I always want to show the difference i dd/mm/yy no matter how long the period is but the maximun value I want to show for days is 1825 or 1826(which is five years depending on if it´s one or two leapyears in the given period). Please help. Give me some hlep how to do the second bit. How do I know to stop on 1825 or 1826.

 

Thank you so much!

 

Link to comment
Share on other sites

date('L', mktime(12, 0, 0, 1,1,'2008'));

 

$startYear = substr($_POST['from_yr'], -2);

$endYear = substr($_POST['to_yr'], -2);

 

$leaps = 0;

for($i=$startYear; $i<=$endYear; $i++) {

if(date('L', mktime(12,0,0,1,1,$i))) $leaps++;

}

 

If i input 28 february 2008 - 28 february 2013 i get 5 years 0 monts and 0 days AND 1827 days and one leap years.

If i input 3 march 2008 - 3 march 2013 i get 5 years 0 monts and 0 days AND 1826 days put only one leap year. <-- Here I only want it to get one leap year.

 

Please help.

 

Thank you!

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.