'Query to convert for DATE in MySQL
Hello I have a question that transpose column type to DATE.
My Origint Data that for transpose to DATE is below. And there type is VARCHAR, structure is MM/DD/YY
how can i transpose to DATE type??
01-05-75
06-04-66
07-05-66
...
Solution 1:[1]
SELECT DATE(CONCAT(
'19', SUBSTRING(col, 7, 2), /* year, assuming all years are between 1900 and 1999) */
'-',
SUBSTRING(col, 1, 2), /* month */
'-',
SUBSTRING(col, 4, 2) /* day */
))
Solution 2:[2]
You can use MySQL STR_TO_DATE function
SELECT
STR_TO_DATE(
CONCAT(LEFT(`date`,6), '19', RIGHT(`date`, 2)),
'%m-%d-%Y'
)
FROM
tab
Here's a fiddle.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | obe |
| Solution 2 | lemon |
