1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Problemstellung:

Für 32Bit und 64Bit Office Versionen

Wie kann ich anhand eines Datums die dazugehörige Jahreszeit ermitteln? 

Function jahreszeit(dtm_tag As Date) As String
'-------------------------------------------------------------------
'--- Josef Syrovatka
'-------------------------------------------------------------------
'--- Errechnet aus einem Datum die zugehörige Jahreszeit
    Dim lng_monat As Long, lng_tag As Long
    jahreszeit = "?"
    lng_monat = Month(dtm_tag)
    lng_tag = Day(dtm_tag)
    '--- Frühling 21.03.-20.06.
    '--- Sommer   21.06.-22.09.
    '--- Herbst   23.09.-21.12.
    '--- Winter   22.12.-20.03.
    If lng_monat = 0 Or IsNull(lng_monat) Then Exit Function
    If lng_tag = 0 Or IsNull(lng_tag) Then Exit Function
    Select Case lng_monat
    Case 1, 2: jahreszeit = "Winter"
    Case 3: If lng_tag <= 20 Then jahreszeit = "Winter" Else jahreszeit = "Frühling"
    Case 4, 5: jahreszeit = "Frühling"
    Case 6: If lng_tag <= 20 Then jahreszeit = "Frühling" Else jahreszeit = "Sommer"
    Case 7, 8: jahreszeit = "Sommer"
    Case 9: If lng_tag <= 22 Then jahreszeit = "Sommer" Else jahreszeit = "Herbst"
    Case 10, 11: jahreszeit = "Herbst"
    Case 12: If lng_tag <= 21 Then jahreszeit = "Herbst" Else jahreszeit = "Winter"
    End Select
End Function

Aufruf:

Dim x As String
x =jahreszeit(#02.04.2004#)

Das Ergebniswäre x = "Frühling"

 

Ähnliche Artikel