Question

Dates , system Month ?

  • 10 January 2024
  • 3 replies
  • 204 views

Badge +1

how to set up system:month.number to look a prevoius month without it giving me 0 in the process

example: if the month is january 01 - 1 it will be 00 i wanted to be 12.
is there a way to make it -1 system:month?
 

$System:Month.Number:toString$-1


3 replies

Userlevel 3
Badge +8

Hi @Arthas03,

In Automation Anywhere, the $System:Month.Number$ variable gives you the current month as a number (1 for January, 2 for February, and so on). If you want to get the previous month, you can subtract 1 from this value. However, as you've pointed out, this can cause an issue when the current month is January (1 - 1 = 0).

To handle this, you can use a conditional statement (If-Else) in your bot. Here's an example:

  1. Set a variable, let's call it PreviousMonth.
  2. Use an If-Else command to check if $System:Month.Number$ is greater than 1.
  3. If it is, subtract 1 from $System:Month.Number$ and assign the result to PreviousMonth.
  4. If it's not (which means the current month is January), set PreviousMonth to 12 (for December).

Here's how the pseudo-code would look:

If $System:Month.Number$ > 1 Then
Set `PreviousMonth` = $System:Month.Number$ - 1
Else
Set `PreviousMonth` = 12
End If

Now, you can use the PreviousMonth variable in your bot to represent the previous month as a number. Please note that this is a workaround and the actual implementation might vary based on the exact requirements and the version of Automation Anywhere you're using.

For more information on using variables and conditional statements in Automation Anywhere, you can refer to the following documentation:

Badge +1

Hi @Arthas03,

In Automation Anywhere, the $System:Month.Number$ variable gives you the current month as a number (1 for January, 2 for February, and so on). If you want to get the previous month, you can subtract 1 from this value. However, as you've pointed out, this can cause an issue when the current month is January (1 - 1 = 0).

To handle this, you can use a conditional statement (If-Else) in your bot. Here's an example:

  1. Set a variable, let's call it PreviousMonth.
  2. Use an If-Else command to check if $System:Month.Number$ is greater than 1.
  3. If it is, subtract 1 from $System:Month.Number$ and assign the result to PreviousMonth.
  4. If it's not (which means the current month is January), set PreviousMonth to 12 (for December).

Here's how the pseudo-code would look:

If $System:Month.Number$ > 1 Then
Set `PreviousMonth` = $System:Month.Number$ - 1
Else
Set `PreviousMonth` = 12
End If

Now, you can use the PreviousMonth variable in your bot to represent the previous month as a number. Please note that this is a workaround and the actual implementation might vary based on the exact requirements and the version of Automation Anywhere you're using.

For more information on using variables and conditional statements in Automation Anywhere, you can refer to the following documentation:

will it work all inside a String assign ?
$vListIndicators1.LegacyAutomation:getLegacyIndexValue($Loop-Counter-1.LegacyAutomation:getDecrementedNumber$)$0$vPreviousMonth$

 

Userlevel 3
Badge +7

Hi @Arthas03

Rather then creating this logic why not you use following actions.

  1. Use “Substract” action from the Datetime Package.
  2. Assign source as system date
  3. Time value to substract as 1
  4. Time Unit a “Month”
  5. And assign the output to the datetime variable

    Now to get the final value in string 

  6. Use “To String” action from datetime package

  7. Pass the source as the output of the above action

  8. Select “Custom format” and type “MM” for month in numbers

  9. Assign the string variable to the output.

     

That’s it. this will give you your desired output in two lines. Converting the Month into number will always give you the proper mathematical output.

 

Hope this helps.

Reply