Tuesday 5 May 2015

Automation Script dates

To add DAYS to date:

For example, in Work Order we have target start date and target finish date:

now we will get the Target Start Date and Target Finish Date as variables tsd" and "tfd respectively.

In automation script, if we want to add two days to "Target Start Date" and copy it into "Target Finish Date"

# First import Calendar
from java.util import Calendar

#Create a Calendar instance
cal = Calendar.getInstance()

#Set calendar date as Target Start Date. Variable is defined in automation script as "tsd"
cal.setTime(tsd);
# ADD TWO DAYS TO TARGET START DATE
cal.add(cal.DATE,2)

#SUBSTRACT TWO DAYS TO TARGET START DATE
cal.add(cal.DATE,-2)

#ADD TWO WEEKS TO TARGET START DATE
cal.add(cal.DATE, 2*7)

#SUBSTRACT TWO WEEKS TO TARGET START DATE
cal.add(cal.DATE, -2*7)

#ADD 4 MONTHS TO TARGET START DATE
cal.add(cal.MONTH,4)

#SUBSTRACT 4 MONTHS TO TARGET START DATE
cal.add(cal.MONTH,-4)

#ADD 5 YEARS TO TARGET START DATE
cal.add(cal.YEAR,5)

#SUBSTRACT 5 YEARS TO TARGET START DATE
cal.add(cal.YEAR,-5)
#SET NEW DATE WITH INCREMENT/DECREMENT FROM CALENDAR TO TARGET FINSIH DATE
tfd = cal.getTime();



 

1 comment:

Unknown said...

elif mc < mb :
cal1 =Calendar.getInstance()
cal1.getTime();
cal.setTime(bd1);
cal.add(cal.YEAR , - cal1.YEAR)
bd = cal.getTime();
mbo.setValue("CDATE",bd)
age= SimpleDateFormat("yy").format(mbo.getDate("CDATE"))
mbo.setValue("AGE",age)
this return 93 why ? it shuld 26

Maximo SOAPUI error javax.xml.ws.WebServiceException

SOAPUI error while sending payload to below url (in cluster environment) http://localhost:9080/meaweb/services/MXASSET Error : <f...