Using Powershell how do you get the weekday number?

Get-Date -UFormat %u

will return formated date.

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


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

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

Tags:

Powershell