What condition to write in Switch case to check the Date

I have a scenario where, Logic /flow of code changing as per the date ,this is for almost 7 to 8 dates . So, I need to check the date when bot runs , if todays date is 1 -then do - print “hello”. If date is 2 then print “welcome”, if date is 3 print “how ru” and so on for till dates 7 or 8 .and for any other date than mentioned dates print “UiPath”

please help me to write the expression in Switch case and the cases also :slight_smile:

TIA

@8b6861dc5e0c9f7008548ca66

Assign activity:
currentDate = DateTime.Now.Day.ToString

Switch activity:
Expression: Convert.ToInt32(currentDate)

Cases:
1:

  • Log Message activity: “Hello”
    2:
  • Log Message activity: “Welcome”
    3:
  • Log Message activity: “How are you”
    4:
  • Log Message activity: “Some other message for date 4”
    5:
  • Log Message activity: “Some other message for date 5”
    6:
  • Log Message activity: “Some other message for date 6”
    7:
  • Log Message activity: “Some other message for date 7”
    8:
  • Log Message activity: “Some other message for date 8”
    Default:
  • Log Message activity: “UiPath”

1 Like

Hi @8b6861dc5e0c9f7008548ca66 ,

You could convert the date to string first like datevariable.Tostring(“dd”). This way you will get the date number which can directly be use in switch like below:
case (1): writeline(“hello”)
case(2): writeline(“welcome”)

I hope this will help you

Hi @8b6861dc5e0c9f7008548ca66

currentDate As DateTime = DateTime.Now

dayOfMonth As Integer = currentDate.Day

If dayOfMonth = 1 Then
    // Print "Hello"
   
ElseIf dayOfMonth = 2 Then
    // Print "Welcome"
    
ElseIf dayOfMonth = 3 Then
    // Print "How are you"
  
// Continue the pattern for other dates
Else
    // For any other date, print "UiPath"
    
End If

Cheers!!

1 Like

Hi @8b6861dc5e0c9f7008548ca66


Hope it helps!!

hi @lrtetala , I used this in switch case :slight_smile: thank you !

1 Like

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