NLCJ Posted June 27, 2010 Share Posted June 27, 2010 Hello, I've got some SQL queries and in a row in the table is a date. Formatted: dd-mm-yyyy. Now I have to check if that date is in the past, so how should i do it? Using '<' doesn't work and Google ain't helping a lot... Regards, Chris Quote Link to comment Share on other sites More sharing options...
Mchl Posted June 27, 2010 Share Posted June 27, 2010 Using '<' doesn't work That's because you're storing your date in VARCHAR() or similar datatype, instead of proper DATE. Fix this and it'll work. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 27, 2010 Share Posted June 27, 2010 When using dates in MySQL, you should store them in columns as a DATE type, which is formatted as YYYY-MM-DD, then date comparisons will work fine. You can display them any way you want. Ken Quote Link to comment Share on other sites More sharing options...
NLCJ Posted June 27, 2010 Author Share Posted June 27, 2010 But if I insert them using YYYY-MM-DD, how can I display them then like: DD-MM-YYYY? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 27, 2010 Share Posted June 27, 2010 SELECT DATE_FORMAT(`field`, '[format parameters]') AS date Quote Link to comment Share on other sites More sharing options...
NLCJ Posted June 27, 2010 Author Share Posted June 27, 2010 SELECT DATE_FORMAT(`field`, '[format parameters]') AS date I don't need it directly in the SQL query, I just need PHP to check it (using if and else). I've found a function using reformat_date, maybe this will work? Quote Link to comment Share on other sites More sharing options...
NLCJ Posted June 27, 2010 Author Share Posted June 27, 2010 I've fixed it using reformat_date. Thanks for your suggestions though! Quote Link to comment 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.