created a simple crud application on nodejs and mysql. but have one problem, cant display the date without time and in the proper format.
{
"id": 1,
"name": "Rick Sanchez",
"dob": "1960-05-20T19:00:00.000Z",
"phone": "84351548898",
"comments": "Genius in the galaxy"
},
in the phpmyadmin, the date in the dob i chose as the datetime format.
3
Answers
You can use
toLocaleDateString()
method,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
You could create a date Object from the string with
const myDate = new Date(myString)
and then use a method likemyDate.toLocaleDateString()
to retrieve only the date partI believe you should use the moment.js library which is more powerful and has great options(like format).
In your case, you can do the following.