Forum Moderators: open

Message Too Old, No Replies

Date Comparison

Why will my dates not compare correctly

         

webworker us

2:23 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



I am working on a new project and need to compare my records by fiscal year. What I have so far is rather messy, and sadly doesn't work.

if cstr(formatdatetime(Master("RecordEndDate"),2)) > cstr(formatdatetime(dateadd("yyyy",+(years - 1),formatdatetime("6/30/1998",2)),2)) and cstr(formatdatetime(Master("RecordEndDate"),2)) < cstr(formatdatetime(dateadd("yyyy",+(years + 1),formatdatetime("6/30/1998",2)),2)) then

I have tried all kinds of formatting statements but so far it doesn't show any of my records as being within the date range. (most dates are 5/5/2008). Years is a counter I'm running through that goes 10 years.

Any suggestions or hints would be very appriciated,

Casey

mattglet

7:35 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

if (DateValue(Master("RecordEndDate")) > DateValue(dateadd("yyyy",+(years - 1),"6/30/1998"))) and (DateValue(Master("RecordEndDate")) < DateValue(dateadd("yyyy",+(years + 1),"6/30/1998"))) then

You need to compare dates, not strings. You can't use operators on string values. I did this quickly, so make sure I didn't delete a parens that was needed.

webworker us

1:03 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



It worked. Thanks. I'll use the datevalue() from now on.

Casey