top of page

An alternative method to perform DateTime operations

💡 If you are familiar with PowerShell, the action Run PowerShell script might be an useful alternative to performing DateTime operations.

Problem Description


You need to perform some datetime operations, e.g. getting the previous month in the MMMM format. One method is to use the Date time actions as follows:



One drawback to the above solution is that your script can get cluttered pretty fast, especially if you need to perform many datetime operations.

Solution


If you are familiar with Microsoft PowerShell, you will know that the Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several .NET and UNIX formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs.



Hence, you can use the action Run PowerShell script to perform the required DateTime operation easily. For the same example, the alternative solution would be as follows:


The PowerShell code to run would be:

[CultureInfo]::CurrentCulture.DateTimeFormat.GetMonthName((Get-Date).AddMonths(-1).Month)

Do note that you may need to trim the output first, i.e. use %PreviousMonth.Trimmed% instead of %PreviousMonth%.

Additional Information


  • Last updated on: 28 Jan 2023

  • Tested version(s): 2.27.177.22340

  • Prerequisites: None

  • Dependencies: None

  • Known issues: None

Robotic Process Automation Singapore

CFB Bots is a leading technology service provider in the fast-growing field of Intelligent Automation. We partner with large enterprises in their Digital Transformation journey and help them and their employees thrive in the Future of Work.

NAVIGATE
CONTACT US
STAY CONNECTED

Singapore

CFB Bots Pte Ltd

Registration No.: 201705263H

77 High Street

#05-09, High Street Plaza

Singapore 179433

​

T: +65 6909 2099

E: enquiries@cfb-bots.com

​​

Malaysia

CFB Bots Sdn Bhd

Registration No.: 202401045826 (1591672-X)

Suite: 33-01, 33rd Floor

Menara Keck Seng

203 Jalan Bukit Bintang

55100 Kuala Lumpur

​​

T: +60 39 388 0352

E: my@cfb-bots.com

​

Australia

T: +61 2 8880 5998

E: au@cfb-bots.com

Join our mailing list to get the latest insights on automation

  • LinkedIn Social Icon
  • Facebook Social Icon
  • Twitter Social Icon
  • Instagram Social Icon
  • YouTube Social  Icon
TS Master Logo.png

© 2017-2025 CFB Bots Pte Ltd. All Rights Reserved. Tel: (65) 6909 2099 | Email: enquiries@cfb-bots.com | Privacy Policy | Terms of Use

bottom of page