Skip to main content
Question

Dates , system Month ?

  • January 10, 2024
  • 4 replies
  • 984 views

Forum|alt.badge.img+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

4 replies

Forum|alt.badge.img+8
  • Automation Anywhere Team
  • January 10, 2024

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:


Forum|alt.badge.img+1
  • Author
  • Cadet | Tier 2
  • January 10, 2024

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$

 


Abhay Naik
Forum|alt.badge.img+8
  • Navigator | Tier 3
  • January 10, 2024

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.


Forum|alt.badge.img
  • Cadet | Tier 2
  • November 24, 2025

In Automation Anywhere, if the Bot running in Current Month and if you want Previous Month From date & To Date, Please Refer Image

for example :

Step1: Bot Running in Current Month - Get Current Month

Step2: Current Month - 1 = Previous Month LastDate ( you will get dd.MM.yyyy -→ ToDate)

Step3: Extract Only Month in Previous Month LastDate

Step4: String Assign directly like 01/ExtractedMonth/System.year → FromDate