Karunamurthy
(Karunamurthy Narasimhan)
September 30, 2023, 6:39pm
1
I want to create a If condition. Can anyone help?
I need to identify if the month is between January to November of current year.
Example 1: For the year 2023, I need to find if the month is between Jan to Nov “then” I need to add 31 March 2024, “else” 31 March 2025
Thus, For the year 202X, I need to find if the month is between Jan to Nov “then” I need to add 31 March 202(X+1), “else” 31 March 202(X+2)
1 Like
Hi
Hope this helps
Use a assign activity before this if condition like this
currentMonth = DateTime.Now.Month
Where currentMonth is a variable of type int32
Now in if condition
If currentMonth >= 1 AndAlso currentMonth <= 11 Then
' Month is between Jan and Nov
' Calculate the date for 31st March of (X+1) year
resultDate = New DateTime(currentDate.Year + 1, 3, 31)
Else
' Month is Dec
' Calculate the date for 31st March of (X+2) year
resultDate = New DateTime(currentDate.Year + 2, 3, 31)
End
resultDate
variable should have a DateTime
Cheers @Karunamurthy
1 Like
Yoichi
(Yoichi)
September 30, 2023, 11:59pm
3
Hi,
FYI, another approach : The following expression returns what you expect directly, without IF activity.
new DateTime(currentDate.Year+1-CInt(currentDate.Month>11),3,31)
Regards,
Parvathy
(PS Parvathy)
October 1, 2023, 12:40am
4
Hi @Karunamurthy
Drag and drop an “Assign” activity to your workflow to get the current month and year:
currentMonth = DateTime.Now.Month
currentYear = DateTime.Now.Year
Add an “If” activity and set the condition to check if the currentMonth
is between 1 (January) and 11 (November):
currentMonth >= 1 AndAlso currentMonth <= 11
Inside the “Then” branch of the If activity, add an “Assign” activity to calculate the result year:
resultYear = currentYear + 1
In the “Else” branch of the If activity, add another “Assign” activity to calculate the result year:
resultYear = currentYear + 2
Finally, add one more “Assign” activity outside of the If activity to create the result date:
resultDate = New DateTime(resultYear, 3, 31)
For your simple understanding
Assign=> currentMonth = DateTime.Now.Month
Assign=> currentYear = DateTime.Now.Year
If
currentMonth >= 1 AndAlso currentMonth <= 11
Then
Assign=> resultYear = currentYear + 1
Else
Assign=> resultYear = currentYear + 2
End If
Assign=> resultDate = New DateTime(resultYear, 3, 31)
Hope it helps
Hope this clarifies
Let us know for further clarification @Karunamurthy
Hi,
please follow below steps and also check workflow.
Assign: CurrentYear = DateTime.Now.Year
Assign: CurrentMonth = DateTime.Now.Month
If: CurrentMonth >= 1 AndAlso CurrentMonth <= 11
Assign: ResultDate = New DateTime(CurrentYear + 1, 3, 31)
Else
Assign: ResultDate = New DateTime(CurrentYear + 2, 3, 31)
Message Box: ResultDate
Here is an workflow:
Main.xaml (8.9 KB)
system
(system)
Closed
October 18, 2023, 5:54am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.