search

Home  >  Q&A  >  body text

How to change SQL date format to YYYY-MM-DD?

I have a column named "start_date" with data type "DATE". On my database table it appears as "YYYY-MM-DD" format, but when I pull the data from the project (using node.js) I get the result as "YYYY-MM-DDT22:00:00.000 Z". How do I change the format to "YYYY-MM-DD"? I tried FORMAT(start_date, "yyyy-MM-dd") but it didn't work...

I know we can usually change the format from client side using moment like moment(start_date).format("YYYY-MM-DD") but I am trying to do this from server side.

P粉713846879P粉713846879333 days ago584

reply all(1)I'll reply

  • P粉021854777

    P粉0218547772024-01-05 14:50:31

    You can use the DATE_FORMAT function to format dates.

    SELECT DATE_FORMAT(start_date, '%Y-%m-%d') FROM table_name;
    

    reply
    0
  • Cancelreply