掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
実動日数を計算するには? (ID:78642)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
2年程前にカレンダーソフトみたいなものを 作ったときのソースがまだあったので、 それにちょっと手を加えて 祝祭日を判断する物をここに書きます。 ちなみに春分の日と秋分の日は特殊な祝日なので (天文学的に、太陽の位置を精密に求めなければわからないので) いつまでこれであってるかは忘れました。 たしか2099年までこれで良かったはず。(^_^;) Private Function Holiday(pDate As Date) As String Dim HDayName(14) As String Dim HDayList(14) As Date Dim TempDate As Date Dim intYear As Integer Dim intindex As Integer intYear = Year(pDate) '******************* '* 祝日の設定 * '******************* HDayName(0) = "元旦" HDayList(0) = DateSerial(intYear, 1, 1) HDayName(1) = "成人の日" If intYear <= 1999 Then HDayList(1) = DateSerial(intYear, 1, 15) Else TempDate = DateSerial(intYear, 1, 1) HDayList(1) = TempDate - Weekday(TempDate) _ + IIf(Weekday(TempDate) <= 2, 9, 16) End If HDayName(2) = "建国記念の日" HDayList(2) = DateSerial(intYear, 2, 11) HDayName(3) = "春分の日" HDayList(3) = DateSerial(intYear, 3, Fix(20.8431 _ + 0.242194 * (intYear - 1980) - Fix((intYear - 1980) / 4))) HDayName(4) = IIf(intYear <= 1988, "天皇誕生日", "みどりの日") HDayList(4) = DateSerial(intYear, 4, 29) HDayName(5) = "憲法記念日" HDayList(5) = DateSerial(intYear, 5, 3) HDayName(6) = "国民の休日" HDayList(6) = DateSerial(intYear, 5, 4) HDayName(7) = "こどもの日" HDayList(7) = DateSerial(intYear, 5, 5) HDayName(8) = "海の日" If intYear <= 2001 Then HDayList(8) = IIf(intYear <= 1995, 0, DateSerial(intYear, 7, 20)) Else TempDate = DateSerial(intYear, 7, 1) HDayList(8) = TempDate - Weekday(TempDate) _ + IIf(Weekday(TempDate) <= 2, 9, 23) End If HDayName(9) = "敬老の日" HDayList(9) = DateSerial(intYear, 9, 15) HDayName(10) = "秋分の日" HDayList(10) = DateSerial(intYear, 9, Fix(23.2488 _ + 0.242194 * (intYear - 1980) - Fix((intYear - 1980) / 4))) HDayName(11) = "体育の日" If intYear <= 1999 Then HDayList(11) = DateSerial(intYear, 10, 10) Else TempDate = DateSerial(intYear, 10, 1) HDayList(11) = TempDate - Weekday(TempDate) _ + IIf(Weekday(TempDate) <= 2, 9, 16) End If HDayName(12) = "文化の日" HDayList(12) = DateSerial(intYear, 11, 3) HDayName(13) = "勤労感謝の日" HDayList(13) = DateSerial(intYear, 11, 23) HDayName(14) = "天皇誕生日" HDayList(14) = IIf(intYear <= 1988, 0, DateSerial(intYear, 12, 23)) '******************* '* 祝日の判断 * '******************* For intindex = 0 To UBound(HDayName) If pDate = HDayList(intindex) Then Holiday = HDayName(intindex) Exit Function End If Next intindex '********************** '* 振替休日の判断 * '********************** If Weekday(pDate) = vbMonday Then For intindex = 0 To UBound(HDayName) If pDate - 1 = HDayList(intindex) Then Holiday = "振替休日" Exit Function End If Next intindex End If '************************************ '* 祝日が見つからなかった時の処理 * '************************************ Holiday = "" End Function このプロシージャに日付を渡せば祝日の名前が返ってきます。 ちなみにプロジェクトを下に置いておきます。 http://oku_newtype.tripod.co.jp/calendar.lzh 「春分の日」と「秋分の日」の計算方法が載っているところ。 http://www.threeweb.ad.jp/~center/shunbun.html
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.