Berdasarkan benda link ini:
https://stackoverflow.com/questions/59001682/powershell-get-the-first-and-last-day-of-the-previous-month
Aku cuba dapatkan hari pertama bulan lepas dan bulan ini:
###previous month
$YEARMONTH = Get-Date -Format "yyyyMM"
$prev_month = (Get-Date).AddMonths(-1)
Write-Host "This month $($YEARMONTH)"
Write-Host "Last month $($prev_month)"
$CURRENTDATE=GET-DATE -Hour 0 -Minute 0 -Second 0
$MonthAgo = $CURRENTDATE.AddMonths(-1)
$FIRSTDAYOFMONTH=GET-DATE $MonthAgo -Day 1
$PREV_FIRSTDAYOFMONTH=GET-DATE $MonthAgo -Day 1
$CURRENT_FIRSTDAYOFMONTH=GET-DATE $CURRENTDATE -Day 1
$LASTDAYOFMONTH=GET-DATE $FIRSTDAYOFMONTH.AddMonths(1).AddSeconds(-1)
$FIRSTDAYOFMONTH.ToString("MM/dd/yyyy HH:mm:ss")
$LASTDAYOFMONTH.ToString("MM/dd/yyyy HH:mm:ss")
Write-Host "PREV_FIRSTDAYOFMONTH $($PREV_FIRSTDAYOFMONTH)"
Write-Host "CURRENT_FIRSTDAYOFMONTH $($CURRENT_FIRSTDAYOFMONTH)"
This month 202109
Last month 08/23/2021 17:08:05
08/01/2021 00:00:00
08/31/2021 23:59:59
PREV_FIRSTDAYOFMONTH 08/01/2021 00:00:00
CURRENT_FIRSTDAYOFMONTH 09/01/2021 00:00:00
Comments
Post a Comment