The code that I wrote seems to be having trouble with comparing dates. It always goes to the else statement when it passed the completed part.
The fields Startdate and Duedate are both date fields.
Does anyone know what I could have done wrong?
— code —
' check status
If ( note.getitemvalue("completed")(0) <> "" ) Then
result = "Complete"
Elseif Isempty(note.startdate) Then
result = "Not planned"
Elseif Today > Format(note.DueDate(0), "dd/mm/yyyy") Then
result = "Overdue"
Elseif Today >= Format(note.StartDate(0), "dd/mm/yyyy") Then
result = "Current"
Elseif Today >= Format(note.StartDate(0), "dd/mm/yyyy") Then
result = "Future"
Else
result = "should not see this..."
End If
— code end —
Kind regards,
Arjan ten Brinke
Subject: Date comparison
Format() returns a string, not a date. Try using CDat() instead.
Subject: RE: Date comparison
If I do that, it gives a ‘type mismatch’
— code —
' check status
If ( note.getitemvalue("completed")(0) <> "" ) Then
result = "Complete"
Elseif Isempty(note.startdate) Then
result = "Not planned"
Elseif Today > Cdat(note.DueDate) Then
result = "Overdue"
Elseif Today >= Cdat(note.StartDate) Then
result = "Current"
Elseif Today >= Cdat(note.StartDate) Then
result = "Future"
Else
result = "should not see this..."
End If
— code end —
Subject: RE: Date comparison
You need to put note.DueDate(0) instead of note.DueDate.
Notes considers all fields to be arrays in the back-end document
CDat also requires that there is something that it can convert into a date in the field. So if it is equal to “”, you will still get a type mismatch
HTH
Mike
Subject: RE: Date comparison
The isempty in the if makes sure it is empty. At least, that’s what i thougt it would do?I tried with the (0) but unfortunately that also didn’t do the trick.
— code —
' check status
If ( note.getitemvalue("completed")(0) <> "" ) Then
result = "Complete"
Elseif Isempty(note.startdate) Then
result = "Not planned"
Elseif Isempty(note.duedate) Then
result = "Not planned"
Elseif Today > Cdat(note.DueDate(0)) Then
result = "Overdue"
Elseif Today >= Cdat(note.StartDate(0)) Then
result = "Current"
Elseif Today >= Cdat(note.StartDate(0)) Then
result = "Future"
Else
result = "should not see this..."
End If
— code end —
Subject: RE: Date comparison
Which line do you get the type mismatch on???
Subject: RE: Date comparison
I see the problem but I don’t quite understand.
The field which he hangs on is empty. But I thought that this line would prevent that.
— code —
Elseif Isempty(note.startdate) Then
— code end —
But it does not stop at that line. Do you see anything wrong with that line?
Subject: RE: Date comparison
I don;t use IsEmpty. I would write if note.Startdate(0)=“” instead
Subject: RE: Date comparison
Aaaah… that was it!!Thank you very much. Now I can go home and rest! ;-).
Kind regards,
Arjan ten Brinke
Subject: RE: Date comparison
debugger stops at this line
— code —
Elseif Today > Cdat(note.DueDate(0)) Then
— code end —