Reputation: 37
I have migrated data from old DB to new DB where date was taken as varchar
, I have migrated data successfully but problem in date . In old DB the format of date is 25-01-02
where 25
is day 01
is month and 02
is year. But my script converted it to 2025-01-02
. How can I fix it in my SQL?
TEST case:
DATE OUTPUT
2025-05-01 2001-05-25
2002-08-16 2016-08-02
2031-01-01 2001-01-31
2028-08-16 2016-08-28
2001-05-01 2001-05-01
Upvotes: 0
Views: 318
Reputation: 15057
You can it easy convert with STR_TO_DATE like this:
SELECT STR_TO_DATE('25-01-02', '%d-%m-%y');
sample
mysql> SELECT STR_TO_DATE('25-01-02', '%d-%m-%y');
+-------------------------------------+
| STR_TO_DATE('25-01-02', '%d-%m-%y') |
+-------------------------------------+
| 2002-01-25 |
+-------------------------------------+
1 row in set (0,00 sec)
mysql>
See the Manual: https://mariadb.com/kb/en/mariadb/str_to_date/
Upvotes: 1