I started to SET
my dates to (%d. %M %Y)
.
But now I cant find them with:
SELECT value FROM _data WHERE dates >= "01. October 2012" AND <= "01. December 2016"
The default DATE_FORMAT
was YYYY-MM-DD hh:mm:ss.000
before the UPDATE
comand.
Can someone explain whats the problem here?
I tried the it with LIKE '%<date>%'
but it changed nothing.
3
Answers
Use yyyy-MM-dd format which is independent of date settings:
EDIT: A date is a date and %d %M %Y is just a display format. Underlying data is still a date. You shouldn’t fall into a mistake like storing them as string.
Here is a DBFiddle demo.
Use STR_TO_DATE to convert dates to a proper format.
"01. October 2012"
is a column name in SQL, because of the double quotes. MySQL allows these for strings, too, but you should always use single quotes for string literals.'01. October 2012'
is a string. It starts with the characters ‘0’ then ‘1’ then ‘.’ then ‘ ‘ then ‘O’. This comes after'01. April 2023'
for instance, because ‘A’ < ‘O’. This is not at all what you want. You don’t want to work with strings. You want to deal with dates.DATE
followed by a string in the format ‘yyyy-mmdd’.>= startdate
and< enddate + 1
for date ranges.AND <= "01. December 2016"
. This is not a condition. You forgot to tell the DBMS which column shall be less or equal the string literal.DATE
, not as strings. If your table column is a string type, this should be fixed first.The query you finally want should then be: