The CreatorCon Call for Content is officially open! Get started here.

Calculate difference in date field in years

anupama8
Tera Expert

I have two fields which are date type (note date/time).

I want to get the difference in years. I am not able to find any function which gives result in years?

Can someone suggest?

7 REPLIES 7

My field is only Date type. It is not a DateTime field.


Instead of GlideDateTime use GlideDate and use only yyyy-mm-dd format without time.


pawel_st -then-
Giga Guru

Recently had to do similar thing.



var start = new GlideDateTime(current.start_date);


var end = new GlideDateTime(current.end_date);


var diff = GlideDateTime.subtract(end, start).getNumericValue();


var diff_year = diff/1000/60/60/24/365; // more or less year in milliseconds.