PowerTip: Add Days, Hours, and Minutes to Current Time

Summary: Use Windows PowerShell to easily add days, hours, and minutes to the current time.

Hey, Scripting Guy! Question How can I use Windows PowerShell to add one day, two hours, and thirty minutes to the current date and time?

Hey, Scripting Guy! Answer 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

Comments (10)

  1. Chen V says:

    Fastest methos [DateTime]::Now.Add(1).AddHours(2).AddMinutes(30) – 40 Milliseconds of execution time

  2. Thank you all including Chen and Piotr as well!

  3. Really good! Did not know about New-TimeSpan; I used Get-Date

  4. Piotr Siódmak says:


  5. Ed Wilson says:

    @Pitor now that is cool. I did not know that I could do that. Thank you for sharing.

  6. tomk says:

    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.

  7. MaxFLipz says:

    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?

  8. Rajiv says:


    works as well!

  9. thanks says:

    gives some additional options from my usual:

    $thedate = get-date -date $(get-date).adddays(-90) -format yyyy-MM-dd

Skip to main content