0

I want to display the date timestamp retrieved from a MySQL database in a HTML table dynamically. I have an array of dates. I am getting date in the following format:

Mar 10, 2014 6:40:45 AM

How can I get the date as it is and represent it in my HTML table using JavaScript?

2 Answers 2

2

Assuming that Mar 10, 2014 6:40:45 AM is your input date format, This code will help:

var myDate = new Date('Mar 10, 2014 6:40:45 AM');
var reqDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());
console.log(reqDate);

output

3/10/2014
Sign up to request clarification or add additional context in comments.

Comments

0

Given your clarification that you cannot change the format of the incoming date, you need something like this:

var dateParts = isoFormatDateString.split("-");
var jsDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2].substr(0,2));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.