Month condition

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)

Date Condition

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

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,

Hi @Karunamurthy

  1. Drag and drop an “Assign” activity to your workflow to get the current month and year:
currentMonth = DateTime.Now.Month
currentYear = DateTime.Now.Year
  1. 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
  1. Inside the “Then” branch of the If activity, add an “Assign” activity to calculate the result year:
resultYear = currentYear + 1
  1. In the “Else” branch of the If activity, add another “Assign” activity to calculate the result year:
resultYear = currentYear + 2
  1. 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)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.