Calculate Number of Days based on today's date

busireddy
Tera Contributor

Hi All,

Could any one help me on following requirement.

How do I get number of days on current date. For example today date is 1-6-2022 and result I want is Number of days is 6

 

 

1 ACCEPTED SOLUTION

I tried this on my PDI, and Working fine.

 

var currentdate = new GlideDate();
gs.print(currentdate.getDayOfMonthNoTZ());

 

Output:

*** Script: 6

View solution in original post

8 REPLIES 8

I tried this on my PDI, and Working fine.

 

var currentdate = new GlideDate();
gs.print(currentdate.getDayOfMonthNoTZ());

 

Output:

*** Script: 6

hey,

was that useful? Please mark correct answer if it works.

shloke04
Kilo Patron

Hi,

Please use below to get the result:

 var start = new GlideDateTime('Date 1 Field Value');
  var end = new GlideDateTime('Date 2 Field Value');
  var diff = GlideDateTime.subtract(start, end);
  var days = diff.getRoundedDayPart();

  gs.info(days);

 

For example something like below:

var start = new GlideDateTime('2021-05-17 00:00:00');
var end = new GlideDateTime('2021-05-18 23:59:59');
var diff = GlideDateTime.subtract(start, end);
var days = diff.getRoundedDayPart();

gs.print(start);
gs.print(end);
gs.print(days);
*** Script: 2021-05-17 00:00:00
*** Script: 2017-05-18 23:59:59
*** Script: 2

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Did you try the solution proposed above, works for me. let me know if you are facing an issue and also a screenshot of the fields of your form will be good to have along with script which you have written.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke