When I try to convert a string to a date in MYSQL, I'm getting weird results.
SELECT
'2017-06-20' d
,CAST('2017-06-20' as DATE) d1
,DATE_FORMAT('2017-06-20', '%Y-%m%-%d') d2
,STR_TO_DATE('2017-06-20', '%Y-%m-%d') d3
,DATE('2017-06-20') d4
On my machine, d2 is the only correct date, i.e. it generates 2017-06-20
. The rest, i.e. d1, d3 and d4, generate 06/19/2017
. Why? I'm especially perplexed by STR_TO_DATE