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 Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/ 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. Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077876 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 Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077877 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? Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077878 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 Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077879 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? Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077880 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! Link to comment https://forums.phpfreaks.com/topic/205992-date-in-the-past/#findComment-1077882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.