problem with datediff and dateadd function

374 Views Asked by At
If DateDiff(DateInterval.Day, moDoBooking.m_CurrentDay, moDoBooking.m_BaseDay) _
          > DateDiff(DateInterval.Day, DateAdd(DateInterval.Day, _
          Convert.ToDouble(moDoBooking.oBooking.oFacility.ADAYS), moDoBooking.m_BaseDay), _
          moDoBooking.m_BaseDay) Then

This condition won't satisfy with these values:

moDobooking.m_CurrentDay = 2/3/2011
moDobooking.m_BaseDay = 22/02/2011
moDoBooking.oBooking.oFacility.ADAYS = 1

You might say this is dead-easy but honestly it's late here and my head is not working at all! Could AnyOne tell me why is that?

2

There are 2 best solutions below

2
On BEST ANSWER

I would expect your boolean condition to always return false.

Why? Because the difference in days between two days will always be less than the difference + 1.

0
On

I'm not sure what you are looking for but I suspect the sign is opposite what you expect because the values are negative. As someone previously mentioned your if statement is obfuscated. Do yourself a favor and create interim variables to hold the values and then compare. You need at least 3 more variables before it will become obvious what you are trying to do.