Calculate Time Difference between Dates in PowerShell

14 views 0 comments last modified about 30 days ago Raymond Tang

lite-log 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

image

The C# way

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

Output

image

Add comment

Comments (0)

No comments yet.