JavaScript date calculation with months difference -


i want calculate new date adding number of months specific date.

for example:

i have date "06/30/2012" (30th june 2012), , number of months "2" or "3" months.

now want function gets both values , returns date 2 months after specified date.

please show me how can achieved.

you can try putting code, has need date addition/subtraction

date.prototype.add = function (sinterval, inum){       var dtemp = this;       if (!sinterval || inum == 0) return dtemp;       switch (sinterval.tolowercase()){         case "ms":           dtemp.setmilliseconds(dtemp.getmilliseconds() + inum);           break;         case "s":           dtemp.setseconds(dtemp.getseconds() + inum);           break;         case "mi":           dtemp.setminutes(dtemp.getminutes() + inum);           break;         case "h":           dtemp.sethours(dtemp.gethours() + inum);           break;         case "d":           dtemp.setdate(dtemp.getdate() + inum);           break;         case "mo":           dtemp.setmonth(dtemp.getmonth() + inum);           break;         case "y":           dtemp.setfullyear(dtemp.getfullyear() + inum);           break;       }       return dtemp;     }      //sample usage     var d = new date();     var d2 = d.add("d", 3); //+3days     var d3 = d.add("h", -3); //-3hours     var d4 = d.add("mo", 2); //+2 months 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -