Skip to content

Commit b0ab61a

Browse files
bobbytreedsdwheeler
authored andcommitted
Updating Set-Date (#4241)
1 parent 59a5ac5 commit b0ab61a

File tree

5 files changed

+411
-259
lines changed

5 files changed

+411
-259
lines changed

reference/3.0/Microsoft.PowerShell.Utility/Set-Date.md

Lines changed: 90 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,103 @@
11
---
2-
ms.date: 06/09/2017
2+
ms.date: 4/30/2019
33
schema: 2.0.0
44
locale: en-us
55
keywords: powershell,cmdlet
66
online version: http://go.microsoft.com/fwlink/?LinkID=113393
77
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
88
title: Set-Date
99
---
10-
1110
# Set-Date
11+
1212
## SYNOPSIS
1313
Changes the system time on the computer to a time that you specify.
14+
1415
## SYNTAX
1516

1617
### Date (Default)
18+
1719
```
1820
Set-Date [-Date] <DateTime> [-DisplayHint <DisplayHintType>] [-WhatIf] [-Confirm] [<CommonParameters>]
1921
```
2022

2123
### Adjust
24+
2225
```
2326
Set-Date [-Adjust] <TimeSpan> [-DisplayHint <DisplayHintType>] [-WhatIf] [-Confirm] [<CommonParameters>]
2427
```
2528

2629
## DESCRIPTION
27-
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
3230

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.
3736

38-
Description
37+
## EXAMPLES
3938

40-
-----------
39+
### Example 1: Add three days to the system date
4140

4241
This command adds three days to the current system date.
4342
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)
4950
```
5051

51-
Description
52+
### Example 2: Set the system clock back 10 minutes
5253

53-
-----------
54+
This example sets the current system time back by 10 minutes.
5455

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
6264
```
6365

64-
Description
66+
### Example 3: Set the date and time to a variable value
6567

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`.
6770

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.
7673

77-
Description
74+
```powershell
75+
$T = Get-Date
76+
Set-Date -Date $T
77+
```
7878

79-
-----------
79+
### Example 4: Add 90 minutes to the system clock
8080

8181
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+
8494
## PARAMETERS
8595

8696
### -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`.
89101

90102
```yaml
91103
Type: TimeSpan
@@ -100,12 +112,13 @@ Accept wildcard characters: False
100112
```
101113
102114
### -Date
115+
103116
Changes the date and time to the specified values.
104-
You can type a new date in the short date format and a time in the standard time format for your locale.
105-
Or, you can pass a Date-Time object from Get-Date.
117+
You can type a new date in the short date format and a time in the standard time format for your
118+
locale. Or, you can pass a **DateTime** object from `Get-Date`.
106119

107-
If you specify a date, but not a time, Set-Date changes the time to midnight on the specified date.
108-
If you specify only a time, it does not change the date.
120+
If you specify a date, but not a time, `Set-Date` changes the time to midnight on the specified
121+
date. If you specify only a time, it does not change the date.
109122

110123
```yaml
111124
Type: DateTime
@@ -120,21 +133,25 @@ Accept wildcard characters: False
120133
```
121134

122135
### -DisplayHint
123-
Determines which elements of the date and time are displayed.
124136

125-
Valid values are:
137+
Specifies which elements of the date and time are displayed.The acceptable values for this parameter
138+
are:
126139

127-
- date: displays only the date
128-
- time: displays only the time
129-
- datetime: displays the date and time
140+
- **Date**.
141+
displays only the date.
142+
- **Time**.
143+
displays only the time.
144+
- **DateTime**.
145+
displays the date and time.
130146

131147
This parameter affects only the display.
132-
It does not affect the DateTime object that Get-Date retrieves.
148+
It does not affect the **DateTime** object that `Get-Date` retrieves.
133149

134150
```yaml
135151
Type: DisplayHintType
136152
Parameter Sets: (All)
137153
Aliases:
154+
Accepted values: Date, Time, DateTime
138155
139156
Required: False
140157
Position: Named
@@ -144,6 +161,7 @@ Accept wildcard characters: False
144161
```
145162

146163
### -Confirm
164+
147165
Prompts you for confirmation before running the cmdlet.
148166

149167
```yaml
@@ -159,6 +177,7 @@ Accept wildcard characters: False
159177
```
160178

161179
### -WhatIf
180+
162181
Shows what would happen if the cmdlet runs.
163182
The cmdlet is not run.
164183

@@ -175,20 +194,33 @@ Accept wildcard characters: False
175194
```
176195

177196
### CommonParameters
178-
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,
199+
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
200+
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
201+
179202
## INPUTS
180203

181204
### System.DateTime
182-
You can pipe a date to Set-Date.
205+
206+
You can pipe a date to `Set-Date`.
207+
183208
## OUTPUTS
184209

185210
### 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.
187213

188214
## 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.
190215

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.
192224

193225
## RELATED LINKS
194226

0 commit comments

Comments
 (0)