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
The C# way
$current = [System.DateTime]::Now
$end= [System.DateTime]::Now
$diff= $end.Subtract($end)
Write-Output "Time difference is: $diff"
Output
info Last modified by Raymond 6 years ago
copyright
This page is subject to Site terms.
comment Comments
No comments yet.
Log in with external accounts
warning Please login first to view stats information.
article
Calculate Difference/Duration between Two Timestamps in PowerShell
article
List all environment variables in PowerShell
article
Azure PowerShell Runbook Error - Internet Explorer engine is not available
article
Github Action Az Automation PowerShell: Object reference not set to an instance of an object
article
Export CSV File from Azure SQL Databases
Read more (8)