Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Powershell how do you get the weekday number?

Tags:

powershell

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 code below but how do I get the number as there is no DayNumberOfWeek or equivalent property?

(Get-Date).DayOfWeek

I suppose I could use the day name from the code above in a switch statement to convert it to a number but that doesn't seem to be very eloquent.

like image 864
Dave Sexton Avatar asked Feb 27 '13 11:02

Dave Sexton


1 Answers

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
like image 104
CB. Avatar answered Sep 18 '22 07:09

CB.