Datumsfunktionen
Datumsdifferenz
Datumsdifferenz
Public Function DatumsDifferenz(DateStart As Date, DateEnd As Date, Optional interval As String = "d") As Integer 'Debug.Print interval Debug.Print Datum2 DatumsDifferenz = DateDiff(interval, DateStart, DateEnd)End FunctionPublic Function DateDif(Datum1 As Date, Datum2 As Date, Optional interval As String = "d") As Integer DateDiff = DateDiff(interval, Datum1, Datum2)End Function
Jahr, Monat, Tag zu Datum hinzufügen
funktioniert wie: "=DATUM(JAHR(A1);MONAT(A1)+1;TAG(A1))"
DatumAddieren
Public Function DatumAddieren(Datum As Date, plusJahr As Integer, plusMonat As Integer, plusTag As Integer) As Date DatumAddieren = DateSerial(Year(Datum) + plusJahr, Month(Datum) + plusMonat, Day(Datum) + plusTag)End Function
Den X.Tag des Jahres ermitteln
X.Tag des Jahres
Public Function X_Day_of_Year(myDate As Date) As Integer X_Day_of_Year = DateDiff("d", DateSerial(Year(myDate), 1, 1), myDate) + 1End FunctionPublic Function X_Day_of_Year_reverse(XDay As Integer, Jahr As Integer) As Date X_Day_of_Year_reverse = DateSerial(Jahr, 1, 1 + XDay - 1)End Function
Den X. Montag/Dienstag ... eines Jahres ermitteln
X.Montag eines Jahres
Public Function XDay_of_Year(X As Integer, Wochentag As String, Jahr As Integer) As DateDim currentDate As DateDim tmpString As StringDim myCounter As Integer myCounter = 0 currentDate = DateSerial(Jahr, 1, 1)For i = 0 To 365 currentDate = DateSerial(Year(currentDate), Month(currentDate), Day(currentDate) + 1) tmpString = Choose(Weekday(currentDate), "Sonntag", "Montag", "Dienstag", _ "Mittwoch", "Donnerstag", "Freitag", "Samstag") If tmpString = Wochentag Then myCounter = myCounter + 1 End If If X = myCounter Then Exit For End IfNext XDay_of_Year = currentDate End Function
weitere Funktionen
Funktionen, die an anderer Stelle erwähnt werden: