Skip to content

Commit c016930

Browse files
PsCustomObjectPsCustomObject
authored andcommitted
Added new post
1 parent 3c2a3e0 commit c016930

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "PowerShell - Get day of weekday"
3+
excerpt: "In this short post we will see how we can use PowerShell to get an integer representing the number associated with the day of the week for the current date."
4+
categories:
5+
- PowerShell
6+
- Howto
7+
8+
tags:
9+
- PowerShell
10+
- Tips
11+
- HowTo
12+
13+
toc: true
14+
header:
15+
teaser: "/assets/images/PowerShell_Logo.png"
16+
---
17+
18+
## PowerShell Get current date
19+
20+
PowerShell natively supports getting the current, or specific, date via the following cmdlet:
21+
22+
```powershell
23+
Get-Date
24+
```
25+
26+
Which, by default, will produce the following output:
27+
28+
```powershell
29+
Monday, February 21, 2022 10:11:39 PM
30+
```
31+
32+
Cmdlet supports methods which can be used to display/return the day of the week for the selected date
33+
34+
```powershell
35+
(Get-Date).DayOfWeek
36+
```
37+
38+
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
39+
40+
```powershell
41+
(Get-Date).DayOfWeek.value__
42+
43+
# Output
44+
1
45+
```
46+
47+
This is specially handy when inserting data into SQL datbase supporting dates as _TinyInt_ data types.

0 commit comments

Comments
 (0)