Learn about Windows PowerShell
Summary: Use Windows PowerShell to easily add days, hours, and minutes to the current time.
How can I use Windows PowerShell to add one day, two hours, and thirty minutes to the current date and time?
Create a TimeSpan object that represents one day, two hours, and thirty minutes, then add it to the current date and time that Get-Date retrieves:
$ts = New-TimeSpan -Days 1 -Hours 2 -Minutes 30
(get-date) + $ts
@Pitor now that is cool. I did not know that I could do that. Thank you for sharing.
Fastest methos [DateTime]::Now.Add(1).AddHours(2).AddMinutes(30) - 40 Milliseconds of execution time
Thank you all including Chen and Piotr as well!
When I try the Set_date command, I always get this error:
Set-Date : A required privilege is not held by the client
At line:1 char:9
+ set-date <<<<
+ CategoryInfo : NotSpecified: (:) [Set-Date], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand
Can't find any documentation on how to modify PS privileges.
Really good! Did not know about New-TimeSpan; I used Get-Date