0

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.

sassy.M
  • 27
  • 6

1 Answers1

1

You can use DATE_FORMAT function to format the date.

SELECT DATE_FORMAT(start_date, '%Y-%m-%d') FROM table_name;
Fastnlight
  • 922
  • 2
  • 5
  • 16
  • Since the format doesn't change, all it does is casting to string. So this should also work: `cast(start_date as char)` or `concat(start_date)`. – Paul Spiegel Oct 19 '22 at 22:00