In this blog post, I will show you how to calculate how many days have passed between two dates in PowerShell.
Code #1
The first code piece will calculate days since a specific date to today’s date:
Simply change the date next to $start date and run the code.
$startdate = '06-07-2020' $today = get-date $x = New-TimeSpan -Start $startdate -End $today "$($x.days) $("days have passed since") $($startdate)"
Code #2
The second code takes two dates and calculates the difference between them as follow.
simply, change the two values in the top two rows and run the code.
$startdate = '06-07-2020' $today = "28/7/2020" $x = New-TimeSpan -Start $startdate -End $today "$($x.days) $("days have passed since") $($startdate)"