Notifications
Announcements
Scripting.RunVBScript.RunVBScript VBScriptCode: $'''Dim currentDate, firstDayOfCurrentMonth, lastDayOfPreviousMonth, firstDayOfPreviousMonth Dim dateIterator, output \' Get today\'s date currentDate = Date \' First day of current month firstDayOfCurrentMonth = DateSerial(Year(currentDate), Month(currentDate), 1) \' Last day of previous month = day before first of current month lastDayOfPreviousMonth = DateAdd(\"d\", -1, firstDayOfCurrentMonth) \' First day of previous month firstDayOfPreviousMonth = DateSerial(Year(lastDayOfPreviousMonth), Month(lastDayOfPreviousMonth), 1) \' Initialize output output = \"\" \' Iterate from first to last day of previous month dateIterator = firstDayOfPreviousMonth Do While dateIterator <= lastDayOfPreviousMonth output = output & FormatDateTimeCustom(dateIterator) & vbCrLf dateIterator = DateAdd(\"d\", 1, dateIterator) Loop \' Output the result so PAD can capture it WScript.Echo output \' --- Custom format function --- Function FormatDateTimeCustom(d) FormatDateTimeCustom = Right(\"0\" & Day(d), 2) & \".\" & Right(\"0\" & Month(d), 2) & \".\" & Year(d) End Function ''' ScriptOutput=> PreviousMonthDates ScriptError=> ScriptError4 Text.SplitText.Split Text: PreviousMonthDates StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> DatesList
Variables.CreateNewList List=> DateList DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime SET CurrentDay TO CurrentDateTime.Day SET CurrentDayPlus1 TO CurrentDateTime.Day + 1 SET DaysToSubstract TO 0 - CurrentDayPlus1 DateTime.Add DateTime: CurrentDateTime TimeToAdd: DaysToSubstract TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastDayOfLastMonth DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> LastMonth SET LastMonth TO $'''01/%LastMonth.Month%/%LastMonth.Year%''' Text.ConvertTextToDateTime.ToDateTime Text: LastMonth DateTime=> LastMonth SET CurrentLoopDay TO LastDayOfLastMonth.Day LOOP LoopIndex FROM 1 TO CurrentLoopDay STEP 1 Variables.AddItemToList Item: LastMonth List: DateList DateTime.Add DateTime: LastMonth TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastMonth END
{ "Day1ThisMonth": @{formatDateTime(utcNow(),'yyyy-MM-01')}, "Day1LastMonth": @{subtractFromTime(utcNow(), 1, 'Month','yyyy-MM-01')} }
int( first( split( dateDifference( outputs('Current_and_Last_Month_Dates')?['Day1LastMonth'], outputs('Current_and_Last_Month_Dates')?['Day1ThisMonth'] ), '.' ) ) )
From: range(0,outputs('DateDiff_Dates')) Map: { "Date": @{addToTime( outputs('Current_and_Last_Month_Dates')?['Day1LastMonth'], item(), 'Day', 'dd MMM yyyy' // Or 'dd.MM.yyyy' )}, "DayofWeek": @{addToTime( outputs('Current_and_Last_Month_Dates')?['Day1LastMonth'], item(), 'Day', 'dddd' )} }
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime SET CurrentDay TO CurrentDateTime.Day SET CurrentDayPlus1 TO CurrentDateTime.Day + 1 SET DaysToSubstract TO 0 - CurrentDayPlus1 DateTime.Add DateTime: CurrentDateTime TimeToAdd: DaysToSubstract TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastDayOfLastMonth DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> LastMonth SET LastMonth TO $'''01/%LastMonth.Month%/%LastMonth.Year%''' Text.ConvertTextToDateTime.ToDateTime Text: LastMonth DateTime=> LastMonth SET CurrentLoopDay TO LastDayOfLastMonth.Day Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance SET RowNum TO 1 LOOP LoopIndex FROM 1 TO LastDayOfLastMonth.Day STEP 1 Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: LastMonth Column: $'''A''' Row: RowNum DateTime.Add DateTime: LastMonth TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastMonth Variables.IncreaseVariable Value: RowNum IncrementValue: 1 END
Scripting.RunVBScript.RunVBScript VBScriptCode: $'''Dim currentDate, firstDayOfCurrentMonth, lastDayOfPreviousMonth, firstDayOfPreviousMonth Dim dateIterator, output \' Get today\'s date currentDate = Date \' First day of current month firstDayOfCurrentMonth = DateSerial(Year(currentDate), Month(currentDate), 1) \' Last day of previous month = day before first of current month lastDayOfPreviousMonth = DateAdd(\"d\", -1, firstDayOfCurrentMonth) \' First day of previous month firstDayOfPreviousMonth = DateSerial(Year(lastDayOfPreviousMonth), Month(lastDayOfPreviousMonth), 1) \' Initialize output output = \"\" \' Iterate from first to last day of previous month dateIterator = firstDayOfPreviousMonth Do While dateIterator <= lastDayOfPreviousMonth output = output & FormatDateTimeCustom(dateIterator) & vbCrLf dateIterator = DateAdd(\"d\", 1, dateIterator) Loop \' Output the result so PAD can capture it WScript.Echo output \' --- Custom format function --- Function FormatDateTimeCustom(d) FormatDateTimeCustom = Right(\"0\" & Day(d), 2) & \".\" & Right(\"0\" & Month(d), 2) & \".\" & Year(d) End Function ''' ScriptOutput=> PreviousMonthDates ScriptError=> ScriptError4 Text.SplitText.Split Text: PreviousMonthDates StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> DatesList Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: DatesList Column: $'''A''' Row: 1
Thanks for your response. I'm still facing an issue—I'm getting a few dates from February along with March, which shouldn't happen.
What I need is to store only the dates of the previous month (e.g., if the current month is April, I should get only dates from 1st March to 31st March). If the previous month has 30 or 28 days, then the list should reflect that accurately (i.e., 1st to 30th or 28th only).
I also want to store these dates in a variable instead in excel, Each date at a time not all to store in Variable, so I can use them later in an SAP recording. Could you please help me fix this?
Best Regards
**REGION Get the last day of the last month DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime SET CurrentDay TO CurrentDateTime.Day SET DaysToSubstract TO 0 - CurrentDay DateTime.Add DateTime: CurrentDateTime TimeToAdd: DaysToSubstract TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastDayOfLastMonth # Now we should have the last day of last month in a %LastDayOfLastMonth% -variable **ENDREGION **REGION Get the first day of the last month DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> LastMonth SET LastMonth TO $'''01/%LastMonth.Month%/%LastMonth.Year%''' Text.ConvertTextToDateTime.ToDateTime Text: LastMonth DateTime=> LastMonth # Now we should have the first day of last month in %LastMont% -variable **ENDREGION Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance # In the loop add all the dates from the first day to the last day to the excel LOOP LoopIndex FROM 1 TO LastDayOfLastMonth.Day STEP 1 Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: LastMonth Column: $'''A''' Row: LoopIndex DateTime.Add DateTime: LastMonth TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> LastMonth END
What I need is to store only the dates of the previous month (e.g., if the current month is April, I should get only dates from 1st March to 31st March like 1st march,2nd march). If the previous month has 30 or 28 days, then the list should reflect that accurately (i.e., 1st to 30th or 28th only).
I want to store these dates in a variable instead in excel, Each date at a time not all to store in Variable, so I can use them later in an SAP recording. Could you please help me fix this?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
In our never-ending quest to improve we are simplifying the forum hierarchy…
We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Michael E. Gernaey 501 Super User 2025 Season 2
Tomac 323 Moderator
abm abm 237 Most Valuable Professional