Hey folks,
Can anyone tell me what’s wrong with this formula?
if ((dt1.DateOnly >= dt2.DateOnly) and (dt1.DateOnly <= dt3.DateOnly))
I am to grab all documents within a particular range. Such an example would be all documents between 04/01/2008 - 04/30/2008. For whatever reasons, I’m getting results exclusive to the month (04 in this case), but varying years.
Any thoughts? Ideas? Or Suggestions?
Cyg
Subject: LS Date Comparison
You probably only want:
if ((dt1 >= dt2) and (dt1 <= dt3)) then
As Matt pointed out you are then comparing strings and depending upon the user regional settings who knows what you’ll get back as a result.
Remember datatime values is the number of days since Dec 31, 1899 at Midnight. So really don’t need to convert these to “dateonly” as you can compare the numbers alone.
Subject: LS Date Comparison
DateOnly returns a string. Does that help?
Subject: LS Date Comparison
in cases like these, i capture the intended values in temp variables and see what they are, the results can be surprising.
I also use it like this if i need to compare date as strings
format(dt1.dateonly, “yyyy/mm/dd”)…
Subject: LS Date Comparison
When I make these sorts of date range comparisons, I always use the .TimeDifference method of the NotesDateTime object, because it always returns a long integer value. So let’s say that dt1 is your base date, dt2 your startdate and dt3 your end date you could do something like this:
If (dt1.TimeDifference(dt2) >= 0) and (dt1.TimeDifference(dt3) <= 0) then
…
execute code
…
End If
If TimeDifference returns a value greater than 0 for the first condition, we know that dt1 is further in the future than dt2. conversely, if the second condition returns a number less than 0, dt1 is not as far in the future as dt3.
This will work more consistently than a string comparison, which compares using string comparison rules, not numeric rules.
hth.
brandt