calculating time till event

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
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

calculating time till event

Post by danwguy »

Ok, so I have a mysql db and I know the day and time of an event, what I need to figure out is how to put that into the database, then use a page to tell how much time is left untill the event happens. A bit more detail, let's say there is a class starting on July 4th @ 1pm how would I go about storing that in a database, then figuring out how long until that day and time, and showing that on the page? Sorry I don't have any code as of right now, as I have never messed with dates and times in mysql or php. I know I can do something like $today = time(); $difference = ($target-$today); $days = (int)($difference/3600); to figure out how many hours until $target, but I am not sure how to store the date/time in mysql and then use it in an equation like that to figure out how long till that day/time. Thank you in advance for your help, and a big thank you to the community here, you guys have taught me and helped me a lot.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: calculating time till event

Post by fugix »

well what i would do is store each section of the date into different fields. like one field for the month(July), one field for the day(4), and one for the time(1pm). Depending on how long in advance you want to alert users, I would set up a statement that compared the date and time in the future...to todays date and time. using the date() and time() functions using the proper formats/timestamps
Post Reply