How to get best from string dateformat to yyyy-mm-dd


#1

I have the following date format: “November 10, 2017, 01:15:58 PM” and want to change it to a more standard “yyyy-mm-dd”. Is there any smart way to go about it?


#2

You could do this

function datereformat(str)
    if str[end-1:end] == "AM"
        dt = DateTime(str, dateformat"UUUU dd, yyyy, HH:MM:SS \A\M")
    else
        dt = DateTime(str, dateformat"UUUU dd, yyyy, HH:MM:SS \P\M")
    end
    return Dates.format(dt, dateformat"yyyy-mm-dd")
end