adriscoll Posted April 27, 2011 Share Posted April 27, 2011 Hello, I have a query that displays a list of events for the year, and am in need of guidance on how to have it only show events that are >= today's date. The 'date' is inserted into the table as a varchar field from javascript code. There was an old blog post about doing something like.... SELECT * FROM calendar WHERE `date` >= NOW() ORDER BY date ASC LIMIT 5 I seem to have trouble in that i believe NOW() will only work with proper datetime entries as opposed to my varchar setup. any help navigating this would be great. Quote Link to comment https://forums.phpfreaks.com/topic/234803-now-datetime-varchar-scramble/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2011 Share Posted April 27, 2011 You didn't show what your date format was. You should store dates using the DATE data type, that's what it is for. Doing so will allow you to directly sort, order, and do greater-than/less-than comparisons on the values. Your data will also take up less storage and your queries will execute faster and will easier to write. Quote Link to comment https://forums.phpfreaks.com/topic/234803-now-datetime-varchar-scramble/#findComment-1206670 Share on other sites More sharing options...
adriscoll Posted April 30, 2011 Author Share Posted April 30, 2011 Everything worked perfectly once i changed the table structure to DATE vs VarChar. Thank you much. Quote Link to comment https://forums.phpfreaks.com/topic/234803-now-datetime-varchar-scramble/#findComment-1208464 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.