Event 5 was probably the second most difficult. My solution is not as elegant as some I've seen but it works. 8)
1: param ([datetime]$dateToCompare = $(Throw "Must specify a Date"))
2:
3: $DatetoCompareYear = $dateToCompare.year
4: $DateToCompareMonth = $dateToCompare.month
5: $days = (New-TimeSpan (get-date).tolongdatestring() $datetocompare.tolongdatestring()).days
6: $months = ((($dateToCompareYear - (get-date).Year) * 12) + ($dateToCompareMonth - (get-date).Month))
7: "Days:$days"
8: "Months:$months"
9:
10: [int]$FullMonths = "{0:N0}" -f $((New-TimeSpan $(get-date) $datetocompare).days / 30.43)
11: [int]$Leftoverdays = "{0:N0}" -f $($days - ($fullmonths * 30.43))
12:
13: "Months/Days: $FullMonths / $leftoverDays"
No comments:
Post a Comment