Formatting JSON Data

Jimbo99999 used Ask the Experts™
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:

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?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
what about :
$("#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

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