Hello Guest (Login?) Inbox (0) P2L Credits (0) My Tutorials (0) Faves (0) Settings Logout
CategoriesTutorials CommentsPodcast Media
Login to use this feature.
15760
2D Graphics
 
 
 
 
189
Databases
 
 
 
 
 
 
 
 
Tutorial Tools
Tutorial Tools - Tutorials
Tutorial Tools - Source Sites

Feb 5th, 2007
1
by
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.
 
Reply Report
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.
 
Reply Report
Post a comment
You must be logged in to post a comment!

Click here to login.

 
Post Comment Back Bold Italic Underline Link Code Box Post Comment
Newsletter
Want to get the inside scoop and the latest news on Pixel2life? Click Subscribe below and sign up for our Newsletter!

Subscribe
News

Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top