0
votes

I am having trouble comparing dates. The if statement in my code is saying the endDate is not less even though it is. For example, if the endDate is 2/20/2017 and startDate 2/22/2017 the if statement says endDate is not lest but it is.

    Dim startDate As Date
    Dim endDate As Date

        startDate = DateValue(Me.dueDateTxt)
        endDate = DateValue(Me.shippedDate)

        If (endDate < startDate) Then
            Debug.Print "It is less"
        Else
            Debug.Print "not less"
        End If

I have also tried

    If Me.dueDateTxt < Me.ShippedDate Then
    If CDate(startDate) < CDate(endDate) Then        
    If Format(startDate, "mm/dd/yyyy") < Format(endDate, "mm/dd/yyyy") Then
    If DateDiff(d, startDate, endDate) > 0 Then

I am missing something somewhere thank you in advance for the help!

EDIT: I figured out what the problem was. I have a function to eliminate holidays and weekends. That function was swaping my startDate and endDate. Thank you everyone for your help and suggestions.

1
Have you tried international date,yyyy-mm-dd? - Fionnuala
I have not tried that yet. My dates that are implemented from the text boxes come up as mm/dd/yyyy. Would I have to change the format before comparing them? - Kevin
In VBA it is always a good idea to use international date formats. You can use FORMAT to get this. - Fionnuala

1 Answers

1
votes

Your first block of code works fine for me.

Have you set the format of the text boxes(?) as 'Short Date' for example?