

|
Login to use this feature.
|
![]() Feb 5th, 2007
1
You say :
We simply divide $nrSeconds by the corresponding number of seconds of a day, a week and a year. But chances of getting an integer number when dividing are pretty small
.. you should explain why ...
I've tested your script with this date "03-25-2007" and '03-26-2007' and it's give "0 days" instead of 1 !!. Because of a daylight-saving-time, the number of seconds between this 2 dates is not 86400 but is 82800 (1 day minus 1 hour). I think your script should use round() instead of foor() for calculing the number of days. Next, you can use the nb of day divided by 7 to calculate the number of weeks :
$nrDaysPassed = round($nrSeconds / 86400); // because a day is 86400 +/- 3600 seconds (think of daylight saving time).
$nrWeeksPassed = floor($nrDaysPassed / 7); // a week is always 7 days: floor is nessesary because "/" operator always return a float
For the nb of years, the scripts may also be false in some circumtances.
Feb 6th, 2007
2
Weird. When I wrote the tutorial I knew that it would have problems with leap years but apparently I forgot to write that down.
The problem can be solved but it would take some more additional if clauses. If I simply use the round() function as you mention then it wouldn't work well on other dates. Why? Because if let's say I use round() on 3.67 days then the script will echo 4 which is not correct.
If I can find the time I will make a function that will correctly deal with leap years.
Thank you for you comment.
![]() |
Coolest design bundle - 39 design goodies just Download 39 design goodies value 5 for just . This offer is available for just 7 days so hurry up!
January 3rd, 2012
Pixel2Life's new Facebook page!
December 23rd, 2011
Our TOP members! Special thanks to Donna, 13lueMage, Jaymz, Rc69, Jamie Huskisson, Bug... and all our most active members.
December 21st, 2011
Should P2L Tutorials have a "Tagging" system?
December 15th, 2011
Want to suggest a new category or a new feature on Pixel2life?
December 13th, 2011
Improvements in the Forums
|















