Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use DATE_FORMAT function to format the date.

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading