PoshCode Logo PowerShell Code Repository

Difference between
modified post 6889 by dfdsdf on Mon 8th May 04:09 and
original post 6887 by Dan In Philly on Fri 5th May 15:41
Showold version | new version | both versions

    
1-
Clear
1+
2-
$start = Read-Host "Start date (mmddyyyy)"
2+
3-
    $startY = $start.Substring(4,4)
4-
    $startM = $start.Substring(0,2)
5-
    $startD = $start.Substring(2,2)
6-
    $startDate = $startY+"-"+$startM+"-"+$startD
7-
$end = Read-Host "  End date (mmddyyyy)"
8-
    $endY = $end.Substring(4,4)
9-
    $endM = $end.Substring(0,2)
10-
    $endD = $end.Substring(2,2)
11-
    $endDate = $endY+"-"+$endM+"-"+$endD
13-
$timespan = [datetime]$endDate - [datetime]$startDate
15-
If($timespan.Days -gt 365) {[string]$yrs1 = $timespan.days/28/13}
16-
    Else { $yr1 = $timespan.Days / 365.25
17-
        $yrs1 = [string]$yr1 }
18-
$yrs2 = $yrs1.split(".")
19-
$Years = $yrs2[0]
20-
$mnth1 = "." + $yrs2[1]
21-
$mnth2 = [math]::Round($mnth1,5)
22-
If($timespan.Days -gt 365) {$mnth3 = $mnth2 * 13}
23-
    Else {$mnth3 = $mnth2 * 12}
24-
$mnth4 = [string]$mnth3
25-
$mnth5 = $mnth4.split(".")
26-
$Months = $mnth5[0]
27-
$days1 = "." + $mnth5[1]
28-
$days2 = [math]::Round($days1,5)
29-
If($timespan.Days -gt 365) {$Days = [math]::Truncate(($days2 * 24) - 1)}
30-
    Else {$Days = [math]::Round($days2 * 30)}
32-
Write-Host $years "years, "$months "months, "$days "days"

ContributeMost Recent Contributions (feed)

Contribute ... Next Page