You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Set-Date cmdlet changes the system date and time on the computer to a date and time that you specify.
28
-
You can specify a new date and/or time by typing a string or by passing a DateTime or TimeSpan object to Set-Date.
29
-
To specify a new date or time, use the Date parameter.
30
-
To specify a change interval, use the Adjust parameter.
31
-
## EXAMPLES
32
30
33
-
### Example 1
34
-
```
35
-
C:\PS>Set-Date -Date (Get-Date).AddDays(3)
36
-
```
31
+
The `Set-Date` cmdlet changes the system date and time on the computer to a date and time that you
32
+
specify.
33
+
You can specify a new date and/or time by typing a string or by passing a **DateTime** or
34
+
**TimeSpan** object to `Set-Date`. To specify a new date or time, use the **Date** parameter.
35
+
To specify a change interval, use the **Adjust** parameter.
37
36
38
-
Description
37
+
## EXAMPLES
39
38
40
-
-----------
39
+
### Example 1: Add three days to the system date
41
40
42
41
This command adds three days to the current system date.
43
42
It does not affect the time.
44
-
The command uses the Date parameter to specify the date.
45
-
It uses the Get-Date cmdlet to get the current date and time and applies the AddDays .NET method for DateTime objects with a value of 3 (days).
46
-
### Example 2
47
-
```
48
-
C:\PS>set-date -adjust -0:10:0 -displayHint time
43
+
The command uses the **Date** parameter to specify the date.
44
+
45
+
The `Get-Date` cmdlet returns the current date as a **DateTime** object. The **DateTime** object's
46
+
**AddDays** method adds a specified number of days (3) to the current **DateTime** object.
47
+
48
+
```powershell
49
+
Set-Date -Date (Get-Date).AddDays(3)
49
50
```
50
51
51
-
Description
52
+
### Example 2: Set the system clock back 10 minutes
52
53
53
-
-----------
54
+
This example sets the current system time back by 10 minutes.
54
55
55
-
This command sets the current system time back by 10 minutes.
56
-
It uses the Adjust parameter to specify an interval of change and the time change (minus ten minutes) in standard time format for the locale.
57
-
The DisplayHint parameter tells Windows PowerShell to display only the time, but it does not affect the DateTime object that Set-Date returns.
58
-
### Example 3
59
-
```
60
-
C:\PS>$t = get-date
61
-
PS C:\> set-date -date $t
56
+
The **Adjust** parameter allows you to specify an interval of change (minus ten minutes) in the
57
+
standard time format for the locale.
58
+
59
+
The **DisplayHint** parameter tells PowerShell to display only the time, but it does not
60
+
affect the **DateTime** object that `Set-Date` returns.
61
+
62
+
```powershell
63
+
Set-Date -Adjust -0:10:0 -DisplayHint Time
62
64
```
63
65
64
-
Description
66
+
### Example 3: Set the date and time to a variable value
65
67
66
-
-----------
68
+
These commands change the system date and time on local computer to the date and time saved in the
69
+
variable `$T`. The first command gets the date and stores it in `$T`.
67
70
68
-
These commands change the system date and time on the computer to the date and time saved in the variable $t.
69
-
The first command gets the date and stores it in $t.
70
-
The second command uses the Date parameter to pass the DateTime object in $t to the Set-Date cmdlet.
71
-
### Example 4
72
-
```
73
-
C:\PS>$90mins = new-timespan -minutes 90
74
-
PS C:\> set-date -adjust $90mins
75
-
```
71
+
The second command uses the **Date** parameter to pass the **DateTime** object in `$T` to the
72
+
`Set-Date` cmdlet.
76
73
77
-
Description
74
+
```powershell
75
+
$T = Get-Date
76
+
Set-Date -Date $T
77
+
```
78
78
79
-
-----------
79
+
### Example 4: Add 90 minutes to the system clock
80
80
81
81
These commands advance the system time on the local computer by 90 minutes.
82
-
The first command uses the New-Timespan cmdlet to create a TimeSpan object with a 90-minute interval, and then it saves the TimeSpan object in the $90mins variable.
83
-
The second command uses the Adjust parameter of Set-Date to adjust the date by the value of the TimeSpan object in the $90mins variable.
82
+
83
+
The first command uses the `New-TimeSpan` cmdlet to create a **TimeSpan** object with a 90-minute
84
+
interval, and saves it in the `$90mins` variable.
85
+
86
+
The second command uses the **Adjust** parameter of `Set-Date` to adjust the date by the value of
87
+
the **TimeSpan** object in the `$90mins` variable.
88
+
89
+
```powershell
90
+
$90mins = New-TimeSpan -Minutes 90
91
+
Set-Date -Adjust $90mins
92
+
```
93
+
84
94
## PARAMETERS
85
95
86
96
### -Adjust
87
-
Adds or subtracts the specified value from the current date and time.
88
-
You can type an adjustment in standard date and time format for your locale or use the Adjust parameter to pass a TimeSpan object from New-TimeSpan to Set-Date.
97
+
98
+
Specifies the value for which this cmdlet adds or subtracts from the current date and time.
99
+
can type an adjustment in standard date and time format for your locale or use the **Adjust**
100
+
parameter to pass a **TimeSpan** object from `New-TimeSpan` to `Set-Date`.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
197
+
198
+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
201
+
179
202
## INPUTS
180
203
181
204
### System.DateTime
182
-
You can pipe a date to Set-Date.
205
+
206
+
You can pipe a date to `Set-Date`.
207
+
183
208
## OUTPUTS
184
209
185
210
### System.DateTime
186
-
Set-Date returns an object that represents the date that it set.
211
+
212
+
`Set-Date`returns an object that represents the date that it set.
187
213
188
214
## NOTES
189
-
* Use this cmdlet cautiously. Changing the date and time on the computer. The change might prevent the computer from receiving system-wide events and updates that are triggered by a date or time. Use the -WhatIf and -Confirm parameters to avoid errors.
190
215
191
-
You can use standard .NET methods with the DateTime and TimeSpan objects used with Set-Date, such as AddDays, AddMonths and FromFileTime. For more information, see [DateTime Methods](https://msdn.microsoft.com/library/system.datetime_methods) and [TimeSpan Methods](https://msdn.microsoft.com/library/system.timespan_methods) in the MSDN library.
216
+
- Use this cmdlet cautiously when changing the date and time on the computer. The change might
217
+
prevent the computer from receiving system-wide events and updates that are triggered by a date or
218
+
time. Use the **WhatIf** and **Confirm** parameters to avoid errors.
219
+
- You can use standard .NET methods with the **DateTime** and **TimeSpan** objects used with
220
+
`Set-Date`, such as **AddDays**, **AddMonths**, and **FromFileTime**. For more information, see
221
+
[DateTime Methods](/dotnet/api/system.datetime) and
222
+
223
+
[TimeSpan Methods](/dotnet/api/system.timespan) in the MSDN library.
0 commit comments