dweb Posted October 17, 2013 Share Posted October 17, 2013 Hi I need to run a query that does a date range search. My dates are stored as the following format Fri Jan 05 2014 I know how to run a query when the dates are stored as YYYY-MM-DD but I cannot figure out how to run a query with the format my dates are stored in I can't change the format of the fields as it's part of a bigger system Does anyone have any suggestions? Link to comment https://forums.phpfreaks.com/topic/283070-date-range-query/ Share on other sites More sharing options...
Barand Posted October 17, 2013 Share Posted October 17, 2013 You can use STR_TO_DATE() to convert that useless format of yours into the correct yyyy-mm-dd format ... WHERE STR_TO_DATE(mydate, '%a %b %d %Y') BETWEEN d1 AND d2 d1 and d2 should be in yyyy-mm-dd format EG mysql> SELECT STR_TO_DATE('Fri Jan 05 2014', '%a %b %d %Y') as date; +------------+ | date | +------------+ | 2014-01-05 | +------------+ Link to comment https://forums.phpfreaks.com/topic/283070-date-range-query/#findComment-1454350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.