I use datatables.net plugin for jquery to build a grid.
I need to output the column date. From the database I get this:
{ts '2013-05-04 03:21:12'}
I would like to output something as 04-05-2013
I use datatables.net plugin for jquery to build a grid.
I need to output the column date. From the database I get this:
{ts '2013-05-04 03:21:12'}
I would like to output something as 04-05-2013
Split the string up and rearrange it.
var ts = "{ts '2013-05-04 03:21:12'}";
ts = ts.match(/'([^']+)'/)[1]; // or ts.split("'")[1]
var dt = ts.split(" ");
var date = dt[0];
var dateSplit = date.split("-");
var finalDate = dateSplit[2] + "-" + dateSplit[1] + "-" + dateSplit[0];
This is assuming the timestamp will always be in the format you provided (won't have other numbers/characters or be in different order).
' instead, you can deal with the original {ts ...}.', I'd rather use a regex. Anyways, I wasn't sure what the OP actually had access to - whether it was the full string or just the date/time. But that's a good point, so I updated my answer to hopefully accommodate that.{ts ...} is a common way that dates are expressed in some SQL installations. So it's a fair guess that the whole string is available.Here's another method, that takes advantage of Date.parse() and it's support for ISO 8601 formatted dates (which is what you have). I borrowed from @Ian's answer for the variable names.
var ts ="{ts '2013-05-04 03:21:12'}";
var dt = ts.split("'");
var date = new Date(Date.parse(dt[1].replace(' ','T')));
var finalDate = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
alert(finalDate);