IBM Support

How to add or subtract number of days mentioned as an input in a Javascript?

Question & Answer


Question

How to add or subtract number of days mentioned as an input in a Javascript?

Answer

Below is the javascript which will add or subtract number of days mentioned as the input value

i.e. if current date is 10-19-2007 and you want to add or subtract 2 days then pass the value to the variable 'inNoofDays' to add 2 days to current date or to subtract or pass the value -2.

Result of the JS
Adding of 2 days to Current Date: 10-21-2007
Subtracting of 2 days to Current Date: 10-17-2007

+++++++++++++++++++++++++++++++++++

var adddays=parseInt(inNoofDays) // number of days to add or subtract
var newdate = new Date();
newdate.setDate(newdate.getDate() + adddays)

Day = newdate.getDate();
Month = newdate.getMonth() + 1;
Year = newdate.getFullYear();

return Year + '-' + Month + '-' + Day;

+++++++++++++++++++++++++++++++++++

[{"Product":{"code":"SSGR73","label":"IBM Cast Iron Cloud Integration"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF033","label":"Windows"}],"Version":"5.0.1.8;6.1.0.6;6.1.0.9","Edition":"Virtual;Physical;Cloud","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

00000422

Product Synonym

Cast Iron Solution
Cast Iron Operating System
Cast Iron Studio

Document Information

More support for:
IBM Cast Iron Cloud Integration

Software version:
5.0.1.8, 6.1.0.6, 6.1.0.9

Operating system(s):
Windows

Document number:
410655

Modified date:
15 June 2018

UID

swg21453033

Manage My Notification Subscriptions