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