Monday, February 25, 2019

To Add or Subtract Number of days to date field in Siebel Escript

Date Calculations are always tricky to work with . In this post we will see how to add or subtract a particular number of days to a UTC date time field like created date in our example. Once we have added number of days we will again write the result to a UTC date time field

Example:
var nsign="+1";
//Can have two values 1 or -1. 1 is to add to the source date & -1 is to subtract from the source date                   
var sDate:Date;       
//Create a variable sDate as Date object

var nDays=10;
//Adds 10 days

sDate = new Date(Date.parse(GetFieldValue("Created")));
//Store the Created date value in a date object

sDate.setDate(sDate.getDate()+nsign*nDays);
//Add 10 days to Created date

this.SetFieldValue("AABResultDate",Clib.strftime(sDate,"%m/%d/%Y%H:%M:%S",sDate));
// Here we use Clib.strftime to format the date string to a UTC datetime format MMDDYY HH:MM:SS

So if the Created date is 15-02-2019 10:30:00 the field AABResultDate will be set to 25-02-2019 10:30:00.

No comments:

Post a Comment