i want to add years to a date field.....but addYearsLocalTime() & addYearsUTC are not working,so i tried to add years by converting them into seconds and then addSeconds but that one is also not working in an application scope ......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2017 11:55 PM
here is the code i wrote !!
every output is as expected . but the variable "add" is showing output as undefined. unable to add seconds to it.
m writing this code in an application scope.
var warranty_date=new GlideDateTime('2017-12-02 00:00:00'); //warranty date in database
var find_year=warranty_date.getYearLocalTime();
var yrs=2; //value of new warranty years
var secs=0;
var tot=find_year+yrs;
for(var i=find_year;i<=tot;i++)
{
var days_in_year=(i%4==0)?366:365;
secs+=days_in_year*86400; // sec in a day*total days in a year
}
var new_day=new GlideDateTime(warranty_date);
var add=new_day.addSeconds(secs);
gs.info("new: "+add);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 10:14 AM
Hi Gagan,
Can you please try this code?
var warranty_date=new GlideDateTime('2017-12-02 00:00:00'); //warranty date in database
var find_year=warranty_date.getYearLocalTime();
var yrs=2; //value of new warranty years
var secs=0;
warranty_date.addYearsLocalTime(yrs);
gs.print(warranty_date.getDate());
