1

I am trying to find current quarter of year in PowerShell to append in a filename with format yyyyqq.

I have already got current month and week as below:

$WeekYYYYWW = (get-date (Get-Date).AddDays(-7) -UFormat "%Y%V")
$yesterdayMMDDYY=(get-date (get-date).AddDays(-1) -uformat %m%d%Y)
$monthly=(get-date (get-date).AddDays(-1) -uformat %m%Y)
4

4 回答 4

5

另一种方法是:

"$(Get-date -f yyyy)$("{0:00}" -f [Math]::ceiling((Get-date -f MM)/3) )"
于 2013-07-18T11:33:35.893 回答
0

一种方法是:

$yearYYYYQQ = "$(get-date -uformat %Y)$("{0:00}" -f [int]((get-date).month/4) )"
于 2013-07-18T10:09:42.473 回答
0

另一种方式:

$today = Get-Date
$YearYYYYQQ = "{0}{1:d2}" -f ($today.Year, [int][math]::Ceiling($today.Month/3))
于 2013-07-18T10:48:08.213 回答
0
"$([datetime]::Now.Year)$(([math]::Ceiling(([datetime]::Now.Month)/3)).ToString().PadLeft(2,"0"))"
于 2013-08-20T21:30:24.600 回答