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
Is there a way to do something similar to : $dayofweek = (get-date).AddDays(+7) | Select DayOfWeek; $short = (Get-Date).AddDays(+7).ToString('yyyy-mm-dd HH:mm AM/PM') because when I try I get A1/P1. Specifically, I want to add 7 days from Monday, then
Tue-Sun add 1,2,3,4,5,6 days. But keep the Hour set at 1:00 AM. Any ideas?
works as well!