javascript - Adding days to a date - date getting converted to string -


so i'm trying add number of days date, , i'm getting strange issue:

var date = new date();  var newdate = date.getdate() + $('#ddldays option:selected').val();  date.setdate(newdate); 

so if today 09/29/2010, date 29. if user selects "5" ddldays, assume adding strings together, adding 295 days date.

i under impression javascript assume integers? getdate() return string instead of integer?

how can fix this?

if want add selected value day of month (i.e. 29 + 5), need parse string value int:

var newdate = date.getdate() + parseint( $('#ddldays option:selected').val(), 10); 

but if want new date, rather int, result, can this:

date.setdate( date.getdate() + parseint( $('#ddldays option:selected').val(), 10); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -