Wenyi Yan
Wenyi Yan

Reputation: 63

Convert the date in sql

cookie_id       date1     date2
201515207920    080515  2015-08-05
203867695306    072015  2015-07-20

How do I convert the date1 to date2 format (yyyy-mm-dd)?

Can't run it.... notice, My syntax is running at netezze warehouse.

select str_to_date(date1, '%M%d%y')
from abc

18:05:41 [SELECT - 0 row(s), 0.000 secs] [Error Code: 1100, SQL State: HY000] ERROR: Function 'STR_TO_DATE(VARCHAR, UNKNOWN)' does not exist Unable to identify a function that satisfies the given argument types You may need to add explicit typecasts ... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec [0 successful, 0 warnings, 1 errors]

Upvotes: 1

Views: 184

Answers (2)

aldrin27
aldrin27

Reputation: 3407

You can also use:

date('Y-m-d');

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269643

This should work:

select str_to_date(date1, '%m%d%y')

However, you are at the whims of MySQL for converting two digit years to four digit years. You might want to incorporate the right century into the value.

Upvotes: 3

Related Questions