Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top