Login to use this feature.
15760
2D Graphics
2238
3D Graphics
176
Audio Editing
189
Databases
2944
Miscellaneous
4664
Operating Systems
320
Video Editing
7003
Website Development
|
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.
|
April 3rd, 2019
Contact Us page now working!
March 24th, 2019
Tutorial avatars uploading issue fixed
March 22nd, 2019
IP Blacklist banning issue
March 20th, 2019
Operation Fix P2L - March 19th Update
June 15th, 2018
Guess who's coming back to P2L?
|