Punith_8
10 years agoOccasional Contributor
Calculating days to a date
Hi,
I have a scenario where I need to add days which is stored in a variable to a date(YYYY-MM-DD) which again is stored in a variable. The way I try to add, it is concatenating with the date and not adding the days. Below is an example code.
import groovy.time.TimeCategory
use (TimeCategory){
def a= b+ c.days
log.info a
}
I am getting the output as 2015-09-2916 days instead of 2015-11-13
Thanks for the help!
Does the below helps?
import groovy.time.TimeCategory def pattern = 'yyyy-MM-dd' def dateString = '2015-09-29 17:31:54.5454000 -04:00' def b = new Date().parse(pattern,dateString) def c = 16 use (TimeCategory){ def a= b+ c.days println a.format(pattern) }