I have some database where the previous err…person has put the date format in as 20121218, is it possible to use this as a date in mysql so
SELECT substr(week_begin_date,0,4)+'-'+substr(week_begin_date,4,2)+'-'+substr(week_begin_date,6,8)
AS startdate
FROM table
WHERE startdate < now()
As stated in Date and Time Literals:
Therefore
20121218is actually a valid date literal. Therefore:See it on sqlfiddle.
However, for the longer-term, you would be wise to fix your schema (and, obviously, any application code that expects to read values in the existing format):
See it on sqlfiddle.