Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

z.B. Access 2000: Dat(e)Diff-Funktion

Empfohlene Antworten

Veröffentlicht

Hallo, Ihr alle da draußen!

Ich habe eine Frage und eine VBA-Lösung zu folgenden Problem:

Die Abfrage-Funktion "DatDiff" bzw. die VBA-Funktion "DateDiff" liefern ja merkwürdige Ergebnisse...!

Wenn ich ermitteln möchte, wie alt jemand in Jahren ist, gebe ich folgende Funktion z.B. in einer Abfrage ein:

y_Alter_inJahre: DatDiff("jjjj";<Geb.Datum>;Datum())

Annahme: Das Geb.Datum ist der 1. Juli 2000, das heutige Datum ist der 17.05.2002

Der Rückgabewert lautet: 2(!)

Der Mensch ist aber erst 1 (vollendetes) Jahr alt!!

In VBA ist es das gleiche (Intervall="yyyy", und die unterschiedlichen Datumsangaben D/USA spielen hier keine Rolle)!

Eine Möglichkeit besteht in folgendem Modul:

*****

Function MyDateDiff(sIntervall As String, dDatum1 As Date, Optional dDatum2 As Date = #12/31/1899#) As Long

Dim iDateDir As Integer

Dim dDateStore As Date

Dim iCounter As Long

'Besser: "IsMissing" (Hat bei mir aber nicht funktioniert!)

'Wenn kein zweites Datum übergeben wird:

If dDatum2 = #12/31/1899# Then

dDatum2 = Date

End If

'Bewegung durch die Zeit: Vorwärts oder rückwärts?

If dDatum1 < dDatum2 Then

'Datum1 chronologisch vor Datum2 --> vorwärts

iDateDir = 1

Else

'Datum2 chronologisch vor Datum1 --> rückwärts

iDateDir = -1

End If

'Abfangen einiger Fehlermöglichkeiten:

If UCase(sIntervall) = "J" Or UCase(sIntervall) = "JJJJ" Or UCase(sIntervall) = "Y" Then

sIntervall = "yyyy"

End If

If UCase(sIntervall) = "T" Then

sIntervall = "d"

End If

'Zähler initialisieren

'=-1 w/ Fußgesteuerter Schleife: Zähler + 1 (und DatumSpeicher + Intervall)

' Dann Test, ob Datum2 über-/unterschritten.

' Annahme: Beim ersten Test Bedingung nicht erfüllt.

' --> kein volles Intervall aber Zähler+1=0 (i.O.)

iCounter = -1

dDateStore = dDatum1

Do

dDateStore = DateAdd(sIntervall, iDateDir, dDateStore)

iCounter = iCounter + 1

Loop While (dDateStore <= dDatum2 And iDateDir = 1) Or (dDateStore >= dDatum2 And iDateDir = -1)

'Ausgabe negativer Zahlen, wenn Zeitbewegung rückwärts

MyDateDiff = iCounter * iDateDir

End Function

*****

Ich habe nicht unter Programmier-Hilfe geschaut, ob dort bereits eine ähnliche Lösung existiert!

Ich möchte mich hier nur verewigen, da ich das obige Modul den seminar-Teilnehmern als "Free-Function" mitgebe.

Ich habe auch nicht getestet, ob das Problem auch unter Excel und anderen Office-Produkten besteht.

An die beiden Moderatoren:

Evtl. verschieben nach "AnwendungsProgramme". Danke

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.