@Raju25
Method1:
Using PAD Switch and Parse actions

Code:
SET Inputstring TO $'''1 hour ago'''
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Text.ParseText.RegexParse Text: Inputstring TextToFind: $'''(\\d+)''' StartingPosition: 0 IgnoreCase: False OccurrencePositions=> Positions Matches=> Matches
SWITCH Inputstring.Trimmed
CASE Contains($'''hour''', False)
DateTime.Add DateTime: CurrentDateTime TimeToAdd: $'''-%Matches[0]%''' TimeUnit: DateTime.TimeUnit.Hours ResultedDate=> DateOutput
CASE Contains($'''day''', False)
DateTime.Add DateTime: CurrentDateTime TimeToAdd: $'''-%Matches[0]%''' TimeUnit: DateTime.TimeUnit.Days ResultedDate=> DateOutput
CASE Contains($'''month''', False)
DateTime.Add DateTime: CurrentDateTime TimeToAdd: $'''-%Matches[0]%''' TimeUnit: DateTime.TimeUnit.Months ResultedDate=> DateOutput
CASE Contains($'''year''', False)
DateTime.Add DateTime: CurrentDateTime TimeToAdd: $'''-%Matches[0]%''' TimeUnit: DateTime.TimeUnit.Years ResultedDate=> DateOutput
END
Method 2:
Try to .net solution below suggested. Pass your input into .net scripts and it will return the expected output.

.Net code

Code:
SET Inputstring TO $'''1 year ago'''
SET ConvertDatetime TO $'''%''%'''
Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.CSharp Script: $''' if (input.EndsWith(\"hour ago\") || input.EndsWith(\"hours ago\"))
{
int hours = int.Parse(input.Split(\' \')[0]);
returndatetime=DateTime.Now.AddHours(-hours);
}
else if (input.EndsWith(\"day ago\") || input.EndsWith(\"days ago\"))
{
int days = int.Parse(input.Split(\' \')[0]);
returndatetime = DateTime.Now.AddDays(-days);
}
else if (input.EndsWith(\"week ago\") || input.EndsWith(\"weeks ago\"))
{
int weeks = int.Parse(input.Split(\' \')[0]);
returndatetime = DateTime.Now.AddDays(-7 * weeks);
}
else if (input.EndsWith(\"month ago\") || input.EndsWith(\"months ago\"))
{
int months = int.Parse(input.Split(\' \')[0]);
returndatetime = DateTime.Now.AddMonths(-months);
}
else if (input.EndsWith(\"year ago\") || input.EndsWith(\"years ago\"))
{
int years = int.Parse(input.Split(\' \')[0]);
returndatetime = DateTime.Now.AddYears(-years);
}
''' @'name:input': Inputstring @'type:input': $'''String''' @'direction:input': $'''In''' @'name:returndatetime': $'''''' @'type:returndatetime': $'''Datetime''' @'direction:returndatetime': $'''Out''' @returndatetime=> ConvertDatetime
Thanks,
Deenuji Loganathan 👩💻
Automation Evangelist 🤖
Follow me on LinkedIn 👥
-------------------------------------------------------------------------------------------------------------
If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏