Formatting JSON Data

Jimbo99999
Jimbo99999 used Ask the Experts™
on
Good Day Experts!

I am working on one of my node/express/sequelize/mysql projects and not sure how to format some JSON data.  The data is returned to my js file and I am displaying it in a modal form.  The data is displaying in the modal format but my date(with no time) is coming form the db and not displaying how I want it to.  

I am looping through the JSON and here is the line of code I am using to display the date:
 $("#modal-data").append("<p><b>Payment Type:</b> " + data[i].paymentType + "</p>");

Here is how it is displaying:
2019-11-24T00:00:00.000Z

I have been unable to find a solution to achieve the date with nothing after it.  Can you help point me in the right direction?

Thanks,
jimbo99999
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
what about : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
$("#modal-data").append("<p><b>Payment Type:</b> " + data[i].paymentType.substring(0,10) + "</p>");

Open in new window

Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
If you want to work with the date object you can do this
Extend the Date object with a custom format function
Date.prototype.customFormat = function() {
  return this.getFullYear() + '-' + 
    ('0' + (this.getMonth() + 1)).substr(-2) + '-' + 
    ('0' + this.getDate()).substr(-2);
}

var dt = new Date(data[i].paymentType);
$("#modal-data").append("<p><b>Payment Type:</b> " + dt.customFormat() + "</p>");

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial