Page 1 of 1
Event Dates
Posted: Thu Jun 30, 2011 5:06 pm
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.
Re: Event Dates
Posted: Thu Jun 30, 2011 5:22 pm
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.
Re: Event Dates
Posted: Thu Jun 30, 2011 5:25 pm
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())
Re: Event Dates
Posted: Thu Jun 30, 2011 6:00 pm
by jacek
UNIX_TIMESTAMP(NOW())
can just be
UNIX_TIMESTAMP()
Re: Event Dates
Posted: Fri Jul 01, 2011 3:44 pm
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
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.