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

Ankur Swami
Tera Guru

Hi,

 

You can calculate the difference between 2 dates. 

 

Try writing below in background scripts. And use according to your requirement.

 

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);

not like this.. it's calculate based on today date suppose today date is 1-6-2022  and I want system will return number of days is 6

Do you need this from year start or month start.

for an example today is 5-02-2022, So from the year start it is 36 days.

But if we calculate from the month start then it will be 5.

So from where you have to calculate.

month start.