Using Powershell how do you get the weekday number?

后端 未结 3 2120
无人及你
无人及你 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:35

    like this:

    ( get-date ).DayOfWeek.value__
    

    I suggest for the future to investigate what properties an object in this way:

    ( get-date ).DayOfWeek | gm -f # gm is an alias for get-member
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-16 16:48
    Get-Date -UFormat %u
    

    will return formated date.

    check http://technet.microsoft.com/en-us/library/hh849887.aspx for more fomats

    0 讨论(0)
提交回复
热议问题