I have a Date value that when tested as = another Date Value should = TRUE as they are the same date. But is is coming up as FALSE and I cannot figure out why. I am trying to figure out if this has something to with variable declarations or whether I am comparing a formatted date to a variable. I have wrapped both dates in CDbl() to see if that helps and the problem still persists.
I set the initial date and comparison date in an array as follows:
Public currentdate As Date
currentdate = DateAdd("h", 0, OldDate)
And Debug.Print currentdate returns "43831"
Later in the routine I add an hour to currentdate and I also add an hour to a date in array called arr using two different approaches: DateAdd() Function and; + 1/24. The two results look exactly the same. But the LEN() function tells a different story. Now to be clear, the value in arr is being added with delimiters which I take out when doing the comparison and I am wondering if that defaults it to a text variable and I am wondering if this is causing the difference in the LEN() results.
currentdate = DateAdd("h", 1, OldDate)
Debug.Print currentdate returns " 43831.0416666667 "
CDbl(arr(0)) + 1 / 24
Debug.Print CDbl(arr(0)) returns " 43831.0416666667 "
?LEN(currentDate) returns 8
?LEN(arr(0)) returns 16
And not surprisingly, when I run a test in an IF stmt to see if the values are the same I get FALSE as a response
If CDbl(currentdate) = CDbl(arr(0)) Then.....(this returns FALSE which is not what I want)
How do I convert currentdate to a value that makes it equal the value in arr(0)? And I need the decimal points in both numbers.
Thanks
I set the initial date and comparison date in an array as follows:
Public currentdate As Date
currentdate = DateAdd("h", 0, OldDate)
And Debug.Print currentdate returns "43831"
Later in the routine I add an hour to currentdate and I also add an hour to a date in array called arr using two different approaches: DateAdd() Function and; + 1/24. The two results look exactly the same. But the LEN() function tells a different story. Now to be clear, the value in arr is being added with delimiters which I take out when doing the comparison and I am wondering if that defaults it to a text variable and I am wondering if this is causing the difference in the LEN() results.
currentdate = DateAdd("h", 1, OldDate)
Debug.Print currentdate returns " 43831.0416666667 "
CDbl(arr(0)) + 1 / 24
Debug.Print CDbl(arr(0)) returns " 43831.0416666667 "
?LEN(currentDate) returns 8
?LEN(arr(0)) returns 16
And not surprisingly, when I run a test in an IF stmt to see if the values are the same I get FALSE as a response
If CDbl(currentdate) = CDbl(arr(0)) Then.....(this returns FALSE which is not what I want)
How do I convert currentdate to a value that makes it equal the value in arr(0)? And I need the decimal points in both numbers.
Thanks