a week ago
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
Answered! Go to Answer.
a week ago
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
Saturday
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.
Monday
To add in an additional solution you can do this in a calculation stage by setting the first day of the month and subtracting by one e.g. if you want to get the number of days in october you would set the date as 01/11/2024 and subtract by one day which shows the date as 31/10/2024.
If its the current month you need then this is the calculation
FormatDate(AddDays(MakeDate("01",FormatDate(AddMonths(Today(), 1),"MM"),FormatDate(Today(),"yyyy")),-1),"dd")
If this writes out to a data item then the data item should be a number or text. If you need to get a month thats not the current month then obviously you would change it to include month and year dynamically so you can find the specific month days you need.
a week ago
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
a week ago - last edited a week ago
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)
Saturday
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.
Sunday
@KodiSrihari any updates ?
Monday
To add in an additional solution you can do this in a calculation stage by setting the first day of the month and subtracting by one e.g. if you want to get the number of days in october you would set the date as 01/11/2024 and subtract by one day which shows the date as 31/10/2024.
If its the current month you need then this is the calculation
FormatDate(AddDays(MakeDate("01",FormatDate(AddMonths(Today(), 1),"MM"),FormatDate(Today(),"yyyy")),-1),"dd")
If this writes out to a data item then the data item should be a number or text. If you need to get a month thats not the current month then obviously you would change it to include month and year dynamically so you can find the specific month days you need.
Monday
Hi @Mohamad_747 @david.l.morris @michaeloneil
Thanks for the Help, It worked.
@Mohamad_747 Your solution also worked but , i need to recheck the Inputs/ formats i was getting some different value.
@david.l.morris Solution also worked , i have utilized the solution.
Thanks,
Srihari