tags:

views:

51

answers:

1

How to split the date,time using java script ? I am getting date,time 2010-05-04 20:13:12.0.But i need only date.

date format mm/dd/yyyy

var cdate = gridline[i=1]["CDATE"];

Now i need cdate as mm/dd/yyyy only.

Please help me.

+1  A: 
function getDateFromString(datestring) {
    var d = new Date(datestring);
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    curr_month++;
    var curr_year = d.getFullYear();
    return curr_date + "-" + curr_month + "-" + curr_year;
}

Source: webdevelopersnotes.com

sshow
where is the `format()` method?
Russ Cam
The `format` method doesn't exist natively on `Date` objects, the only place where I've seen it used before, is on the ASP .NET Ajax framework... Also I think the OP has a string, not a date object...
CMS
Thanks for the pointer, CMS. Updated with a function that should work properly.
sshow