🚀 News: We are launching the Kontext Labs Platform Pilot! Click here to join our pilot program.

Calculate Time Difference between Dates in PowerShell

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"

Output

Open-Live-Writer/PowerShell-Create-TimeSpan_12ECB/image_thumb.png

The C# way

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

Output

Open-Live-Writer/PowerShell-Create-TimeSpan_12ECB/image_thumb_1.png