PDA

View Full Version : String length mismatch



kdog119
03-16-2014, 04:17 PM
Hi,

I cannot figure out why my VBA is returning a result different to what I'm expecting.

I have the following line of code:

numDays = DateDiff("d", Now, LastTestDate)

In debug mode the result is '-111'.

However, when I try to get the length of 'numDays':
strLen = Len(numDays)

It returns the value of '2'.

Can anyone help explain this please?

Cheers,
K.

werafa
03-16-2014, 08:00 PM
what data types are you dealing with?
Check data types, and drop them into a variant type variable if you need to read this.
Setting your data inputs to variables will allow you to read the input data as well - and compare the numbers to your manual calcs.

Also, do you need to use datediff? can you simply subtract one date from the other and take the integer result as your answer (truncate - don't round)
regards
Tim

werafa
03-16-2014, 09:54 PM
without seeing your code, I am not sure of the reason for the difference in string length - but suspect it is due to what data type you are calculating

snb
03-17-2014, 02:02 AM
Is the result correct ?


numDays = DateDiff("d", date, LastTestDate)

the same result


numDays = date- LastTestDate