Forum Discussion
Secretary960
Jul 11, 2024Copper Contributor
Comparing dates in VBA
I have a date entered on a form using this format: "22/02/2024 13:20" and I want to compare it to a specific date to see if it is earlier, later or the same. This needs to be doe in VBA as the respon...
HansVogelaar
Jul 11, 2024MVP
What happens if you use
icompare = #4/1/2025#
(VBA uses USA date format m/d/yyyy)
Also, I'd declare the variables explicitly:
Dim iday As Date, icompare As Date, icomdate As Boolean, ilater As String
Secretary960
Jul 12, 2024Copper Contributor
HansVogelaar Thanks very much. I will have a try with these points later today.
- Secretary960Jul 12, 2024Copper Contributor
@HansVogelaar Thanks very much for your advice. Just had to define the variables as dates as you suggested - did the job.