首页 > 解决方案 > 如何比较文本框中的两个日期?

问题描述

我想比较文本框中的两个日期。

Public Function CourseStatus(ByVal RefDate2 As Variant) As String

    Dim Description As String   
     
    If Len(RefDate2) > 0 And IsDate(RefDate2) Then

        Select Case DateDiff("d", Date, RefDate2)
            Case Is > 60
                CourseStatus = "In Date"
            Case Is > 0
                CourseStatus = "Expiring"
            Case Is = [ParticipationDate]
                CourseStatus = "Not Refreshed"
            Case Else
                CourseStatus = "Expired"
        End Select        
    Else
        CourseStatus = "Please Book"
    End If
        
End Function

如果[ParticipationDate]&[RefDate2]匹配返回“未刷新”作为 CourseStatus。

我需要在运行其余代码之前执行此操作,以提供“日期”“过期”“过期”,如果这些都不适用,则显示“请预订”。

例如
ParticipationDate 1/1/19
RefDate2 1/1/19
CourseStatus “未刷新”

标签: vbams-access

解决方案


你可能会使用这样的东西:

If Len(RefDate2) > 0 And IsDate(RefDate2) Then

    Select Case DateDiff("d", Date, RefDate2)
        Case Is > 60
            CourseStatus = "In Date"
        Case Is > 0
            CourseStatus = "Expiring"
        Case Else
            If DateDiff("d", RefDate2, [ParticipationDate]) = 0 Then
                CourseStatus = "Not Refreshed"
            Else
                CourseStatus = "Expired"
            End If
    End Select        
Else
    CourseStatus = "Please Book"
End If

推荐阅读