Page 1 of 1

Date Based Countdown

Posted: Fri Sep 17, 2010 6:05 pm
by Vegan
I was wondering, if somebody has a code snippet to allow a page to show the number of days to a given event.

For example, today its 105 days until the Bush tax cuts expire.

Once I see how to do it, I can then use the code for other countdowns such as to election days etc.

Re: Date Based Countdown

Posted: Fri Sep 17, 2010 6:40 pm
by McInfo
Timestamps are expressed in seconds. There are 86400 seconds in a day. Use subtraction to find the difference between two timestamps and division to convert seconds to days.

PHP provides a number of date and time functions.

Re: Date Based Countdown

Posted: Fri Sep 17, 2010 9:33 pm
by Weirdan
McInfo wrote:There are 86400 seconds in a day.
Not necessarily. It's not true for days when there's dst / non-dst change. Also you forgot about leap seconds.