erme Posted May 1, 2013 Share Posted May 1, 2013 (edited) Hi, I've created a CMS that enables the user to publish an article which will appear on the site immediately. I need to add in the option to schedule displaying the article. I have a field in the MySQL table for pubished_date. How can I write something in PHP that won't display articles where published_date is in the future / hasn't arrived yet? I could then maybe set up a cron job to run the script every night. Thanks in advance... Edited May 1, 2013 by erme Quote Link to comment https://forums.phpfreaks.com/topic/277494-publishing-in-the-future/ Share on other sites More sharing options...
Solution Jessica Posted May 1, 2013 Solution Share Posted May 1, 2013 Store them as normal. Your script that displays posts, should only query for posts where the published date is in the past. SELECT * FROM posts WHERE published_date <= NOW() etc. Quote Link to comment https://forums.phpfreaks.com/topic/277494-publishing-in-the-future/#findComment-1427507 Share on other sites More sharing options...
erme Posted May 1, 2013 Author Share Posted May 1, 2013 Store them as normal. Your script that displays posts, should only query for posts where the published date is in the past. SELECT * FROM posts WHERE published_date <= NOW() etc. Thanks for your reply. What format will the date and time need to be stored as for this to work? Currently it is stored like this 2013043014:14:35 Quote Link to comment https://forums.phpfreaks.com/topic/277494-publishing-in-the-future/#findComment-1427516 Share on other sites More sharing options...
erme Posted May 1, 2013 Author Share Posted May 1, 2013 Just worked it out. 2008-11-11 12:45:34 Quote Link to comment https://forums.phpfreaks.com/topic/277494-publishing-in-the-future/#findComment-1427522 Share on other sites More sharing options...
Jessica Posted May 1, 2013 Share Posted May 1, 2013 The field should be a DATETIME type Quote Link to comment https://forums.phpfreaks.com/topic/277494-publishing-in-the-future/#findComment-1427525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.