2017-03-01 4 views
0

Ich brauche das Enddatum des Monats bekommen wir sind in ich mit diesem Code versucht.Datum Zeit in ein anderes Format Parsing

$CURRENTDATE=GET-DATE -Format "dd/MM/yyyy" 
$FIRSTDAYOFMONTH=GET-DATE $CURRENTDATE -Day 1 
$LASTDAYOFMONTH=GET-DATE $FIRSTDAYOFMONTH.AddMonths(1).AddSeconds(-1) 

echo $LASTDAYOFMONTH 

Das bin ich das Datum des Ende des Monats gibt. Aber ich brauche es in einem anderen Format (TT/MM/JJJJ). Aber kann nicht scheinen, meinen Kopf drum herum zu bekommen. Ein Schub in die richtige Richtung wäre großartig.

Antwort

1

Anpassung Mike F. Robbins code

$currentDate = Get-Date 
$lastDay = [DateTime]::DaysInMonth($currentDate.Year, $currentDate.Month) 
$lastDayOfMonth = Get-Date ([DateTime]"$($currentDate.Month), $LastDay, $($currentDate.Year)") -Format 'dd/MM/yyyy' 
Write-Host $lastDayOfMonth 
1

Oder wenn Sie möchten, dass Ihre vorhandenen Code verwenden:

$CurrentDate = Get-Date -Format "dd/MM/yyyy" 
$FirstDayOfMonth = Get-Date $CurrentDate -Day 1 
$LastDayOfMonth = Get-Date $FirstDayOfMonth.AddMonths(1).AddSeconds(-1) -Format "dd/MM/yyyy" 

Write-Output $LastDayOfMonth 
Verwandte Themen