Date Based Countdown

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Date Based Countdown

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Date Based Countdown

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Date Based Countdown

Post 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.
Post Reply