Home > Net >  How to change SQL DATE format to YYYY-MM-DD?
How to change SQL DATE format to YYYY-MM-DD?

Time:10-20

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

I understand that we can normally use moment to change the format from a client side like moment(start_date).format("YYYY-MM-DD") but I'm trying to do it from Server-side.

CodePudding user response:

You can use DATE_FORMAT function to format the date.

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