2

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
  • what's the source datatype: a date or a string? Commented Jul 14, 2010 at 22:47

1 Answer 1

2
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

Sign up to request clarification or add additional context in comments.

2 Comments

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...
Thanks for the pointer, CMS. Updated with a function that should work properly.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.