cancel
Showing results for 
Search instead for 
Did you mean: 

Get Number of Days In Month Action Out Put Not Coming.

KodiSrihari
Level 8

Hi Team,

I want to get the No of days in a particular month, but i can't able to get the Number of Days in the Output.

I am providing the Input Month & Year in below format and output data item created as Number.

I have tried the providing the Month as text Like : Jan, January, JANUARY. But no output.

Please suggest if i need to give the input in other format ?

KodiSrihari_0-1732336898271.png

 

 

Thanks,

Srihari

3 REPLIES 3

Hi @KodiSrihari 

Please follow these steps :  

1 - Bring a dataitem with type text name it Date

2 - Bring a dataitem with type number name it nb days

3 - Bring a calculation stage and put this inside it : 

DateDiff(9,
ToDate("1/"&FormatDate([Date],"MM/yyyy"))
,
DateAdd(5, 1, FormatDate([Date],"MM/yyyy"))
)

And store it in bn days like this : 

Mohamad_747_0-1732348053890.png

Your flow should look like this :

Mohamad_747_1-1732348108254.png

If it work for you please mark best answer

Please notice that you can provid the input in this format MMM-YYYY example (Jan-2024)

Mohamad_747_0-1732348506508.png

You can provide also the input with this format MMMM/YYYY (JANUARY/2024)

Mohamad_747_1-1732348686051.png

 

 

david.l.morris
Level 15

That isn't a standard object. If you could paste the code from in the code stage of that action, then we could help you to know what the expected inputs are.

But, otherwise, you could use Mohamad's solution or mine here.

I only made this because somewhat long expressions are funny to me. 😃

I went with a different perspective compared to Mohamad's. My thought is that you'll always have a date to work with such as Today(). In the expression below, the [Date] is the name of the Date data item that holds the date of the month you want to count the days for. The result should be the total number of days in that month.

ToNumber(FormatDate(MakeDate(1,ToNumber(FormatDate([Date], "MM"))+1,ToNumber(FormatDate([Date], "yyyy")))-MakeTimeSpan(1,0,0,0),"dd"))



What it is doing is taking the month and year numbers out of the date and then using them to create a date that is the first of the next month, and then one day is subtracted from that date, resulting in a date that is the last day of the month you are trying to count the days for. And then casting to a number, you essentially have the total number of days.

But frankly, I think I'd just make a new C# code stage to do this, such as this:

 

numOfDays = DateTime.DaysInMonth(Convert.ToInt32(year), Convert.ToInt32(month));

 

 

davidlmorris_0-1732391731366.png

 

davidlmorris_2-1732391757917.png

Of course if you really want it to accept the names of months, then you could do that, but I don't know why you would.

 

 


Dave Morris, 3Ci at Southern Company