PowerShell - Get day of weekday

less than 1 minute read

PowerShell Get current date

PowerShell natively supports getting the current, or specific, date via the following cmdlet:


Which, by default, will produce the following output:

Monday, February 21, 2022 10:11:39 PM

Cmdlet supports methods which can be used to display/return the day of the week for the selected date


There are situations where rather than returning a string with the day name it can be useful to return the number (1 to 7) associated with the day’s name, this can easily be accomplished with the following command


# Output

This is specially handy when inserting data into SQL datbase supporting dates as TinyInt data types.