57392

Date() function in javascript giving NAN-NAN-NAN in firefox and chrome while working fine with IE

Question:

I am calculating on date part through java script , but it is giving NAN-NAN-NAN in Firefox and chrome while working fine in IE . My code is below which is i am using.

var datedisp = $("#txtDateinputBox_startdate").val(); datedisp = datedisp.split("/"); var month = datedisp[0]; var year = datedisp[2]; var dtepart = eval(datedisp[1]); var moddate = dtepart + SetID - 1; var finaldate = month + '-' + moddate + '-' + year; var disp_fdate = new Date(finaldate); //alert(finaldate); var disp_date = disp_fdate.getDate(); //var disp_date = disp_fdate.getUTCFullDate(); var disp_month = disp_fdate.getMonth() + 1; var disp_year = disp_fdate.getYear(); var uidate = eval(disp_month) + '-' +eval( disp_date) + '-' + eval(disp_year);

and then this uidate is using in div creation. Please Help Thanks In Advance

Answer1:

This?

var date, i, string; function date_to_string( date ) { return ( date.getMonth() + 1 ) + '-' + date.getDate() + '-' + date.getFullYear(); } date = new Date( '01/27/2012' ); for ( i = 0; i < 14; i += 1 ) { date.setDate( date.getDate() + 1 ); string = date_to_string( date ); // use string }

<strong>Live demo:</strong> <a href="http://jsfiddle.net/ekaDg/" rel="nofollow">http://jsfiddle.net/ekaDg/</a>

Recommend