powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Set-Date



NAME
Set-Date

SYNOPSIS
Changes the system time on the computer to a time that you specify.

SYNTAX
Set-Date [-Adjust] [-DisplayHint {Date | Time | DateTime}] [-Confirm] [-WhatIf] []

Set-Date [-Date] [-DisplayHint {Date | Time | DateTime}] [-Confirm] [-WhatIf] []


DESCRIPTION
The Set-Date cmdlet changes the system date and time on the computer to a date and time that you specify. You can s
pecify a new date and/or time by typing a string or by passing a DateTime or TimeSpan object to Set-Date. To specif
y a new date or time, use the Date parameter. To specify a change interval, use the Adjust parameter.


PARAMETERS
-Adjust
Adds or subtracts the specified value from the current date and time. You can type an adjustment in standard da
te and time format for your locale or use the Adjust parameter to pass a TimeSpan object from New-TimeSpan to S
et-Date.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-Date
Changes the date and time to the specified values. You can type a new date in the short date format and a time
in the standard time format for your locale. Or, you can pass a Date-Time object from Get-Date.

If you specify a date, but not a time, Set-Date changes the time to midnight on the specified date. If you spec
ify only a time, it does not change the date.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-DisplayHint
Determines which elements of the date and time are displayed.

Valid values are:

-- date: displays only the date
-- time: displays only the time
-- datetime: displays the date and time

This parameter affects only the display. It does not affect the DateTime object that Get-Date retrieves.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm []
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf []
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.DateTime
You can pipe a date to Set-Date.


OUTPUTS
System.DateTime
Set-Date returns an object that represents the date that it set.


NOTES


Use this cmdlet cautiously. Changing the date and time on the computer. The change might prevent the computer f
rom receiving system-wide events and updates that are triggered by a date or time. Use the -WhatIf and -Confirm
parameters to avoid errors.

You can use standard .NET methods with the DateTime and TimeSpan objects used with Set-Date, such as AddDays, A
ddMonths and FromFileTime. For more information, see "DateTime Methods" and "TimeSpan Methods."


-------------------------- EXAMPLE 1 --------------------------

C:\PS>Set-Date -Date (Get-Date).AddDays(3)


Description
-----------
This command adds three days to the current system date. It does not affect the time. The command uses the Date par
ameter to specify the date. It uses the Get-Date cmdlet to get the current date and time and applies the AddDays .N
ET method for DateTime objects with a value of 3 (days).





-------------------------- EXAMPLE 2 --------------------------

C:\PS>set-date -adjust -0:10:0 -displayHint time


Description
-----------
This command sets the current system time back by 10 minutes. It uses the Adjust parameter to specify an interval o
f change and the time change (minus ten minutes) in standard time format for the locale. The DisplayHint parameter
tells Windows PowerShell to display only the time, but it does not affect the DateTime object that Set-Date returns
.





-------------------------- EXAMPLE 3 --------------------------

C:\PS>$t = get-date

C:\PS>set-date -date $t


Description
-----------
These commands change the system date and time on the computer to the date and time saved in the variable $t. The f
irst command gets the date and stores it in $t. The second command uses the Date parameter to pass the DateTime obj
ect in $t to the Set-Date cmdlet.





-------------------------- EXAMPLE 4 --------------------------

C:\PS>$90mins = new-timespan -minutes 90

C:\PS>set-date -adjust $90mins


Description
-----------
These commands advance the system time on the local computer by 90 minutes. 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. 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.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113393
Get-Date
New-TimeSpan