Event Dates

Ask about a PHP problem here.
Post Reply
nxtgaming
Posts: 3
Joined: Fri May 06, 2011 3:37 pm
Location: England
Contact:

Event Dates

Post by nxtgaming »

I can't get around how to do this in my head. I am creating a website where events can be added. I am wanting to display the upcoming events, however I am thinking of this scenario. I have events in the table which have already gone, however using the 'ORDER BY `date`' would show the events that have past still. How would I be able to do this? Would I need to use NOW() and convert the date to a time stamp?

Thanks,
Joe.
One life, live it :D
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Event Dates

Post by bowersbros »

You could always have a 'past_event' and whenever the end time of the date has passed, change it to a 1 with a CRON job, then when you are displaying upcoming events, just add AND past_event = 0 to your mysql query. :)
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
libeco
Posts: 104
Joined: Sat May 07, 2011 9:56 am

Re: Event Dates

Post by libeco »

You will need to do some date calculation and I'm not sure if MySQL is capable of doing so with the DATETIME data type. When using a UNIX TIMESTAMP it's easier to do as you can just add something like
WHERE 'timestamp` > UNIX_TIMESTAMP(NOW())
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Event Dates

Post by jacek »

UNIX_TIMESTAMP(NOW())
can just be
UNIX_TIMESTAMP()
Image
nxtgaming
Posts: 3
Joined: Fri May 06, 2011 3:37 pm
Location: England
Contact:

Re: Event Dates

Post by nxtgaming »

Thanks. I had an idea of how to use, because I had a similar scenario to this in my coursework for A level ICT. That was using Microsoft Access though :roll: Think it was something like <date() or something in that case. I just didn't know how to do it in SQL.
Thanks for your time.
One life, live it :D
Post Reply