これをスクリプトで取得するとしたら...
WSH 用の VBScript だとこんな感じで書けた。今度の 7 月は 15 日。8 日じゃないよ。
[GetWUSched.vbs]
output = Year(Now()) & " 年の Windows Update の年間スケジュール" & vbCrLf
For i = 1 to 12
date1st = DateValue(Year(Now()) & "/" & i & "/01")
If Weekday(date1st) < 4 Then
date2ndTue = DateAdd("d",10-Weekday(date1st),date1st)
Else
date2ndTue = DateAdd("d",17-Weekday(date1st),date1st)
End If
output = output & DateAdd("d",1,date2ndTue) & vbCrLF
Next
WScript.Echo output
For i = 1 to 12
date1st = DateValue(Year(Now()) & "/" & i & "/01")
If Weekday(date1st) < 4 Then
date2ndTue = DateAdd("d",10-Weekday(date1st),date1st)
Else
date2ndTue = DateAdd("d",17-Weekday(date1st),date1st)
End If
output = output & DateAdd("d",1,date2ndTue) & vbCrLF
Next
WScript.Echo output
PowerShell だとこんな感じ? PowerShell は苦手。
[GetWUSched.ps1]
for ($i=1; $i -le 12; $i++) {
$date1st = [datetime]([string](Get-Date).Year + "/" + $i + "/1")
switch ($date1st.DayOfWeek)
{
"Sunday" { $date2ndTue = $date1st.AddDays(9) }
"Monday" { $date2ndTue = $date1st.AddDays(8) }
"Tuesday" { $date2ndTue = $date1st.AddDays(7) }
"Wednesday" { $date2ndTue = $date1st.AddDays(13) }
"Thursday" { $date2ndTue = $date1st.AddDays(12) }
"Friday" { $date2ndTue = $date1st.AddDays(11) }
"Saturday" { $date2ndTue = $date1st.AddDays(10) }
default {}
}
Write-Output $date2ndTue.AddDays(1)
}
$date1st = [datetime]([string](Get-Date).Year + "/" + $i + "/1")
switch ($date1st.DayOfWeek)
{
"Sunday" { $date2ndTue = $date1st.AddDays(9) }
"Monday" { $date2ndTue = $date1st.AddDays(8) }
"Tuesday" { $date2ndTue = $date1st.AddDays(7) }
"Wednesday" { $date2ndTue = $date1st.AddDays(13) }
"Thursday" { $date2ndTue = $date1st.AddDays(12) }
"Friday" { $date2ndTue = $date1st.AddDays(11) }
"Saturday" { $date2ndTue = $date1st.AddDays(10) }
default {}
}
Write-Output $date2ndTue.AddDays(1)
}
・・・
応用編。毎月第三土曜日は、地元消防団の飲み会(ムジン)。年間スケジュールを作成。
[GetMujinDays.vbs]
output = "今年のムジンの年間スケジュール" & vbCrLf
For i = 1 to 12
date1st = DateValue(Year(Now()) & "/" & i & "/01")
date3rdSat = DateAdd("d",21-Weekday(date1st),date1st)
output = output & date3rdSat & vbCrLF
Next
WScript.Echo output
For i = 1 to 12
date1st = DateValue(Year(Now()) & "/" & i & "/01")
date3rdSat = DateAdd("d",21-Weekday(date1st),date1st)
output = output & date3rdSat & vbCrLF
Next
WScript.Echo output
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。