Working with Dates in IBM BPM
Many of us (ibm bpm developers) are wondering on perform certain operation like comparing dates, find difference between dates and such stuff as Date not a simple type but is complex system object. But thanks to bpm suite, the implementation to do these operations are all already in place and if we give simple syntax which we use with simple types it will do the job. Here a some of the operations which I would like to illustrate in this post.
How to Comparing date1 and date2 ?
Comparing dates is as simple as comparing two integers.
Suppose I have two date variables tw.local.date1 and tw.local.date2 .
In order to compare dates we just have to use the statements as shown below.
tw.local.date1 > tw.local.date2 or
tw.local.date1 < tw.local.date2
Above statement will be evaluated to true or false in the similar way when used with integers.
Above statements will consider time stamp as well. If you want to check this irrespective of time, then first set the hours, min and seconds for these dates to same values and then compare. You have to first set hours, seconds and then milliseconds.
How to Compare date to current date ?
For this, first we need to get the current date and store it in a variable.
var currentDate= new TWDate();
then set currentDate and tw.local.date hours , seconds and milliseconds to same value and then compare like above.
To set the hours, minutes and seconds you can use script similar to the one shown below.
tw.local.date.setHours(1);
currentDate.setHours(1);
tw.local.date.setMinutes(1);
currentDate.setMinutes(1);
How to increase the 'n' no of days to a date ?
You can just get the date from tw.local.date and add number of days and set that value to tw.local.date again. This will increase the number of days automatically.Refer to below script.
tw.local.date.setDate( tw.local.date.getDate() + X number of days)
Below scenarios will be automatically taken care when we add days.
scenario1: if tw.local.date = 3/12/2013, if we want to add 3 days to this date, the final date will become 6/12/2013
scenario2: if tw.local.date = 31/12/2013, if we want to add 3 days to this date, the final date will become 3/1/2014. We don't have to explicitly Change the month and year.
scenario2: if tw.local.date = 31/10/2013, if we want to add 3 days to this date, the final date will become 3/11/2013. We don't have to explicitly Change the month.
Hope you find it use full.
Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.
How to Comparing date1 and date2 ?
Comparing dates is as simple as comparing two integers.
Suppose I have two date variables tw.local.date1 and tw.local.date2 .
In order to compare dates we just have to use the statements as shown below.
tw.local.date1 > tw.local.date2 or
tw.local.date1 < tw.local.date2
Above statement will be evaluated to true or false in the similar way when used with integers.
Above statements will consider time stamp as well. If you want to check this irrespective of time, then first set the hours, min and seconds for these dates to same values and then compare. You have to first set hours, seconds and then milliseconds.
How to Compare date to current date ?
For this, first we need to get the current date and store it in a variable.
var currentDate= new TWDate();
then set currentDate and tw.local.date hours , seconds and milliseconds to same value and then compare like above.
To set the hours, minutes and seconds you can use script similar to the one shown below.
tw.local.date.setHours(1);
currentDate.setHours(1);
tw.local.date.setMinutes(1);
currentDate.setMinutes(1);
How to increase the 'n' no of days to a date ?
You can just get the date from tw.local.date and add number of days and set that value to tw.local.date again. This will increase the number of days automatically.Refer to below script.
tw.local.date.setDate( tw.local.date.getDate() + X number of days)
Below scenarios will be automatically taken care when we add days.
scenario1: if tw.local.date = 3/12/2013, if we want to add 3 days to this date, the final date will become 6/12/2013
scenario2: if tw.local.date = 31/12/2013, if we want to add 3 days to this date, the final date will become 3/1/2014. We don't have to explicitly Change the month and year.
scenario2: if tw.local.date = 31/10/2013, if we want to add 3 days to this date, the final date will become 3/11/2013. We don't have to explicitly Change the month.
Hope you find it use full.
Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.
pls post blog on dojo scripts (IBPM8.0)
ReplyDeleteHi Anna
ReplyDeleteplease explain what is dojo toolit, how it is related with coach view
Hi
ReplyDeletei can't able to set the hours and minutes and seconds value as you defined previously.
var currentDate= new TWDate();
currentDate.setHours()(1);
currentDate.setMinutes(1);
Hi VIVEK RAJA
ReplyDeleteTry this:
var currentDate = new TWDate();
log.info("Current Date: " + currentDate);
currentDate.setDate(currentDate.getDate() + parseInt(tw.env.Days));
tw.local.xxx = currentDate;
*******************************************
currentDate.setMinutes(currentDate.getMinutes() + parseInt(tw.env.Mins));
tw.local.xxx = currentDate;
log.info("xxx: " + tw.local.xxx);