yesterday
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 ?
Thanks,
Srihari
yesterday
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 :
Your flow should look like this :
If it work for you please mark best answer
yesterday - last edited yesterday
Please notice that you can provid the input in this format MMM-YYYY example (Jan-2024)
You can provide also the input with this format MMMM/YYYY (JANUARY/2024)
yesterday
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));
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.