jag hittar tusentals svar på hur man får ut antal mellan två datum men inte hur man kan få reda på om ett datum existerar mellan ett start och stop datum. Hade en funktion liggandes just för det ändamålet. Så här löser jag detDatum mellan datum?
Sv: Datum mellan datum?
<code>
Public Function isDateBetweenDates(checkThisDate As String, firstDate As String, secondDate As String) As Boolean
On Error Resume Next
Dim earlyDate As String
Dim lateDate As String
If CDate(firstDate) <= CDate(secondDate) Then
earlyDate = firstDate
lateDate = secondDate
Else
earlyDate = secondDate
lateDate = firstDate
End If
If CDate(checkThisDate) >= CDate(earlyDate) Then
If CDate(checkThisDate) <= CDate(lateDate) Then
isDateBetweenDates = True
Else
isDateBetweenDates = False
End If
Else
isDateBetweenDates = False
End If
End Function
</code>
/MickeSv: Datum mellan datum?
<code>
Option Explicit
Private Sub Command1_Click() ' Testknapp för att kolla om det funkar
'Testknapp skicka (lägsta datum ,högsta datum,datum du vill kolla).
Dim ret As Boolean
ret = DateInRange("1939-06-02", "2004-07-30", "2004-06-02")
If ret = True Then
MsgBox "Datumet ligger inom gränserna"
Else
MsgBox "Datumet ligger utanför gränserna"
End If
End Sub
Private Function DateInRange(ByVal dLow As Date, ByVal dHigh As Date, _
ByVal dCheck As Date) As Boolean
Dim tmpLow As Long
Dim tmpHigh As Long
Dim tmpCheck As Long
tmpLow = CDate(dLow)
tmpHigh = CDate(dHigh)
tmpCheck = CDate(dCheck)
Select Case tmpCheck
Case tmpLow To tmpHigh
DateInRange = True
Case Else
DateInRange = False
End Select
End Function
</code>