Search code examples
mysqldatemysql-date

MySql datetime format change


I have stored date in string format like 'Thu, 24 Dec 2020 07:54:35 GMT'.

Can someone please suggest how to convert this string into YYYY-MM-DD format using MySQL query.

Tried this function :

 str_to_date(dateTime, '%a %d %b %Y %T %x')
    
    DATE_FORMAT(dateTime, '%Y-%m-%d)
    
   DATE(dateTime)

Solution

  • You can just ignore stuff that comes at the end (assuming you're happy to store the time for the given time zone)...

    E.g.

    select str_to_date('Thu, 24 Dec 2020 07:54:35 GMT', '%a, %e %b %Y %T') dt;