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

how to calculate the days count between system date and current date in another field on item

Anuj30
Tera Contributor

We have a catalog item which required to fill a date in one field and then in another field days count need to be show .

for example user filled 25/03/2024

and my system date is 22/03.2024

then days count will appear 3 in days count.

Screenshot attached 

Please suggest how to achieve this 

 

Anuj30_0-1711102694175.png

 

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Anuj30 

 

https://www.servicenow.com/community/itsm-forum/difference-between-2-dates-in-days-in-catalog-client...

 

https://www.servicenow.com/community/developer-forum/how-to-calculate-date-difference-between-two-ca...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

HI AG

 

Will this work to get a difference in catalog field date to system date?

 

Yes, you need to capture System date in Variable and then do calculations. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

SP22
Giga Sage

Hi @Anuj30 ,

function setNumberOfDays() {
  var start = new GlideDateTime('current.u_start_date');
  var end = new GlideDateTime('current.u_end_date');
  var diff = GlideDateTime.subtract(start, end);
  var days = diff.getRoundedDayPart();

  current.u_days_count = days;
}

Thanks
SP