Advertisement
2_2002-2004 Math/ Dates #125464

IsExpired

This code checks the difference between today and any expiration date. Using VB6 functions DateDiff and TimeValue it will evaluate the dates and tell you if we are past the expiration date or not. [Highly commented.]

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Function IsExpired(ExpireDate As Date, ExpireTime As Date) As Boolean
 Dim lngDayDiff As Long
 Dim lngTimeDiff As Long
 
 ' Using DateDiff, a function unique to VB6, we check the
 ' difference between the current date (extracted from Now)
 ' and the expiration date.
 lngDayDiff = DateDiff("d", Now, ExpireDate)
 
 ' If the difference is a negative that means that we are
 ' past the expired date so of course it is expired.
 If lngDayDiff < 0 Then
  GoTo YesExpired
  
 ' If the difference is a zero that means we are ON the
 ' date of expiration. We check the time for a difference
 ' to determine if the time has expired.
 ElseIf lngDayDiff = 0 Then
 
  ' Get the time difference. Note that we use TimeValue(Now)
  ' instead of just Now because it will return the exact
  ' time, not the date/time.
  lngTimeDiff = DateDiff("n", TimeValue(Now), ExpireTime)
  
  ' If the time difference is a negative, we are past it so
  ' the date is expired.
  If lngTimeDiff <= 0 Then
   GoTo YesExpired
   
  ' Otherwise (if we are on the time, or before it) then
  ' we are not yet expired.
  Else
   GoTo NoExpired
  End If
 
 ' Otherwise (if we are on the date, or before it) then
 ' we are not yet expired.
 Else
  GoTo NoExpired
 End If
 
YesExpired:
 IsExpired = True
 Exit Function
NoExpired:
 IsExpired = False
 Exit Function
End Function
Original Comments (3)
Recovered from Wayback Machine