Adding Days to date.
This Seems to be a very simple requirement but It's very tricky. In the following query , I am trying to add some number of days to a DATETIME field and set that date.
For Example :- In Workorder application, If the TARGETSTARTDATE is 10 March 2016. And I want to set the TARGETFINISHDATE to 10 Days later. So my TARGETFINISHDATE would be 20 March 2016
Script Language:Jython
Variable: startdate binding to TARGETSTARTDATE
from java.util import Calendar
startdate = mbo.getDate("TARGETSTARTDATE ")
cal=Calendar.getInstance()
cal.setTime(startdate )
cal.add(Calendar.DATE, +10)
date=cal.getTime()
mbo.setValue("TARGETFINISHDATE ",date,MboConstants.NOACCESSCHECK + MboConstants.NOVALIDATION_AND_NOACTION)
Let me know if it works.
This Seems to be a very simple requirement but It's very tricky. In the following query , I am trying to add some number of days to a DATETIME field and set that date.
For Example :- In Workorder application, If the TARGETSTARTDATE is 10 March 2016. And I want to set the TARGETFINISHDATE to 10 Days later. So my TARGETFINISHDATE would be 20 March 2016
Script Language:Jython
Variable: startdate binding to TARGETSTARTDATE
from java.util import Calendar
startdate = mbo.getDate("TARGETSTARTDATE ")
cal=Calendar.getInstance()
cal.setTime(startdate )
cal.add(Calendar.DATE, +10)
date=cal.getTime()
mbo.setValue("TARGETFINISHDATE ",date,MboConstants.NOACCESSCHECK + MboConstants.NOVALIDATION_AND_NOACTION)
As the script imports java Calendar classes , an instance of Calender object is obtained.
The getInstance() method returns an object that is based on the current time in the default time-zone and default locale of the current JVM where Maximo is running.However, The Calendar object’s time is being set to the Workorder’s targetstartdate attribute value using the Calendar class’ setTime() method.Input variable ‘startdate’ is the parameter to the setTime() method. The scripting framework recognizes that the input variable is bound to a Maximo attribute of DATETIME or DATE type and automatically creates a Java Date object to represent the targetstartdate from the WO record. Thus, input variable startdate is directly passed to setTime().
The getInstance() method returns an object that is based on the current time in the default time-zone and default locale of the current JVM where Maximo is running.However, The Calendar object’s time is being set to the Workorder’s targetstartdate attribute value using the Calendar class’ setTime() method.Input variable ‘startdate’ is the parameter to the setTime() method. The scripting framework recognizes that the input variable is bound to a Maximo attribute of DATETIME or DATE type and automatically creates a Java Date object to represent the targetstartdate from the WO record. Thus, input variable startdate is directly passed to setTime().
Let me know if it works.
Thanks this blog was really help full!!
ReplyDeleteYes Gumte !
ReplyDeletethanks for this post.
ReplyDeletehow about, if I need to add hours to a date?
Thanks! It was really helpful. You should post more often!
ReplyDeletecal1.getTime();
ReplyDeletecal.setTime(bd1);
cal.add(cal.YEAR , - cal1)
its not working how can i do it ?
elif mc < mb :
ReplyDeleteyCurrentDate = SimpleDateFormat("yyyy").format(Date())
yc = yCurrentDate
cal.setTime(bd1);
cal.add(cal.YEAR , - yc)
bd = cal.getTime();
mbo.setValue("CDATE",bd)
age= SimpleDateFormat("yy").format(mbo.getDate("CDATE"))
mbo.setValue("AGE",age)
its not working why ?
elif mc < mb :
ReplyDeletecal1 =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 is working but the result is 93 why ?