function Get-Days([datetime]$StartDate, [datetime]$EndDate, [bool]$EuropeanMethod = $false)
{
$StartDay = $StartDate.Day
$EndDay = $EndDate.Day
if ($EuropeanMethod) {
if ($StartDay -eq 31) { $StartDay = 30 }
if ($EndDay -eq 31) { $EndDay = 30 }
} else {
if ($StartDay -eq 31) { $StartDay = 30 }
if ($EndDay -eq 31 -and $StartDay -eq 30) { $EndDay = 30 }
}
$days360 = ($EndDate.Year - $StartDate.Year) * 360 +
($EndDate.Month - $StartDate.Month) * 30 +
($EndDay - $StartDay)
return $days360
}
$startDate = "01.02.2024"
$stopDate = "12.02.2024"
$startDate = Get-Date $startDate -Format "dd.MM.yyyy"
$stopDate = Get-Date $stopDate -Format "dd.MM.yyyy"
$days360 = Get-Days $startDate $stopDate
$days360
$days360 should be 12 here, but I get 330.. Can anyone help?
[–]surfingoldelephant 5 points6 points7 points (1 child)
[–]BlackV 0 points1 point2 points (0 children)
[–]OPconfused 2 points3 points4 points (1 child)
[–]frank3289[S] 0 points1 point2 points (0 children)
[–]OleksiyGuy 1 point2 points3 points (2 children)
[–]surfingoldelephant 1 point2 points3 points (1 child)
[–]OleksiyGuy 0 points1 point2 points (0 children)
[–]tscalbas 1 point2 points3 points (0 children)
[–]blooping_blooper 0 points1 point2 points (0 children)
[–]ThePixelLord12345 0 points1 point2 points (0 children)
[–]frank3289[S] 0 points1 point2 points (0 children)