Forum Discussion
ikhan543
Jul 18, 2023Copper Contributor
What is wrong with this script?
Hello, I am struggling to find a fix for this script. Can anyone help please? Script's logic: IF day of run is a Monday THEN YYYYMMDD = Friday before -- i.e. 3 days earlier ELSE IF day...
- Jul 18, 2023
Hi ikhan543
The following simple PowerShell script will return a date based on your script logic:
$dayOfWeek = (Get-Date).DayOfWeek $previousDate = if ($dayOfWeek -eq 'Monday') { (Get-Date).AddDays(-3).ToString('yyyyMMdd') } else { (Get-Date).AddDays(-1).ToString('yyyyMMdd') } $previousDate
kevkelly
Jul 18, 2023MCT
Hi ikhan543
The following simple PowerShell script will return a date based on your script logic:
$dayOfWeek = (Get-Date).DayOfWeek
$previousDate = if ($dayOfWeek -eq 'Monday') {
(Get-Date).AddDays(-3).ToString('yyyyMMdd')
} else {
(Get-Date).AddDays(-1).ToString('yyyyMMdd')
}
$previousDate- ikhan543Jul 18, 2023Copper ContributorThank you Kevkelly. Nothing like getting a response from a human 🙂
The script I had was generated by ChatGPT as I don't know Windows scripting and needed a quick solution.