Calculate Time Difference between Dates in PowerShell

visibility 26,301 access_time 4y languageEnglish

PowerShell provides a number of cmdlets to retrieve current date time and to create time span object.

Calculate time difference - CmdLets

$current = Get-Date

$end= Get-Date

$diff= New-TimeSpan -Start $current -End $end

Write-Output "Time difference is: $diff"



The C# way

$current = [System.DateTime]::Now
$end= [System.DateTime]::Now
$diff= $end.Subtract($end)
Write-Output "Time difference is: $diff"



info Last modified by Raymond 4y copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

timeline Stats
Page index 18.84
local_offer Tags