amer99 — 2012-10-07T05:30:22-04:00 — #1
On my website, i want to start a survey on 9th October 12:00 am and close it on 12th Oct 12:00 am. Currently i am bit confused how to achieve this ? i mean how will the script (php) on my website knows that now is the time to mark this survey closed ?
cpradio — 2012-10-07T05:41:29-04:00 — #2
Usually you store the date/time of the start and close in a table or some file, when you read the file to see what survey is available you would put the following as a condition
WHERE start_date <= NOW() AND end_date > NOW()
amer99 — 2012-10-07T05:47:00-04:00 — #3
Sir, basically i want to give a list of surveys that viewers can fill. But i also want to show the surveys that are closed. So do i need a cronjob that will scan the database at regular intervals to see which survey should be closed ? or is there any other way to do it ?
cups — 2012-10-07T06:28:14-04:00 — #4
Where exactly are you storing the start/end dates at the moment?
cpradio — 2012-10-07T06:29:10-04:00 — #5
No, you can just use the end_date column. You "could" use a cronjob, but you don't need to.
SELECT columns, IF (end_date <= NOW(), 'Closed', 'Open') AS Status FROM table WHERE start_date <= NOW()