cancel
Showing results for 
Search instead for 
Did you mean: 

How to get number of days of that current month from Date field

former_member709690
Participant
0 Kudos

I have date field {?Date} but i need to create a formula that can calculate that entire month's number of days . i.e.

Let say this field date is 31/07/2022 so i want to create a formula which give result as "31" which means July got 31 days .

Accepted Solutions (0)

Answers (2)

Answers (2)

DellSC
Active Contributor
0 Kudos

Try something like this:

Local DateVar tmp = {?Date} - Day({?Date}) + 1;  
Day(DateAdd ('m', 1,tmp) - 1) 

The first part of this formula gets the first date of the current month. The second part adds one month to the result of the first part to get the first day of the next month, subtracts 1, which gives the last date of the current month, and then gets the Day value, which is the day number.

I tried this working the last day of the month instead of adding 1 and then subtracting 1, but it doesn't work if the prior month has fewer days than the current month,

-Dell

former_member709690
Participant
0 Kudos

Thanks Dell.

ido_millet
Active Contributor
0 Kudos

Please try this logic (it can handle leap years):

local datevar myDate := cDate("2022-02-18");
Local Datevar StartDate := cDate(Year(myDate), Month(MyDate), 1);
Local Datevar EndDate := cDate(DateAdd('m', 1, StartDate));
EndDate - StartDate;
former_member709690
Participant
0 Kudos

Thanks Ido