I have created a simple form which users submit. Everything works great but I recently found that the
SELECT * FROM `Forms` WHERE `Date` BETWEEN '{$startDate}' AND '{$endDate}'
The column Date is type TEXT. I needed it to be text cause I thought it would be easier to display everything in MM/DD/YY format. Now I dont want to risk changing the data type since the form is working fine.
Example of Date column
01-03-2013
01-04-2013
07-25-2012
08-01-2012
08-01-2012
08-01-2012
08-01-2012
Ex of working Query
SELECT * FROM `Forms` Where `Date` Between '01-08-2012' and '12-12-2012'
Ex of not working Query
SELECT * FROM `Forms` Where `Date` Between '01-08-2012' and '01-04-2013'
Any reason why it would break if the year changes? How can I get it to work even if the year changes.
you can do it like that
DEMO HERE
EDIT :
if you want fix your table here how you do
Add a new column of the appropriate
DATEdata type:Use MySQL’s
STR_TO_DATE()function to populate that new column with the dates held in the old column:Drop the old column (and, if so desired, rename the new one in its place):
Change your application to use this new column.