Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 306 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Powershell how do you get the weekday number?

#1
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.
Reply

#2
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
Reply

#3
Get-Date -UFormat %u
will return formated date.

check

[To see links please register here]

for more fomats
Reply

#4
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
Reply

#5
On Friday the 17th:

(get-date).DayOfWeek.value__

Returns `5`

(Get-Date).DayOfWeek

Returns `Friday`

(Get-Date).Day

Returns `17`
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through