Using Powershell how do you get the weekday number?

后端 未结 3 2141
无人及你
无人及你 2020-12-16 15:48

Using a Powershell date object how do you get the day number of the week, 0 to 6 where 0 would be Sunday and 6 would be Saturday. I know that I can get the day name with the

3条回答
  •  甜味超标
    2020-12-16 16:47

    Well, the DayOfWeek property of a DateTime is not a string but rather a DayOfWeek enum, so the shortest answer is probably

    [Int] (Get-Date).DayOfWeek  # returns 0 through 6 for current day of week
    

    Or

    [Int] [DayOfWeek] "Wednesday"  # returns 3
    

提交回复
热议问题