Forum Discussion

ikhan543's avatar
ikhan543
Copper Contributor
Jul 18, 2023
Solved

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...
  • kevkelly's avatar
    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

Resources