Compare Dates

I am trying to compare two dates.

@If(EndDate < 01/01/2007; Leavehours = 100; Leavehours)

Not working?

Subject: Compare Dates

It depends on how EndDate is stored. If EndDate is a date field, something like this should work:

@If(EndDate < @TextToTime(“01/01/2007”)…

If EndDate is text, then use this:

@If(@TextToTime(EndDate) < @TextToTime(“01/01/2007”)…

Subject: RE: Compare Dates

EndDate is a Date/Time field stored as 01/22/2007

I tried both and nothing?

Subject: RE: Compare Dates

:= assigns a value and = compares a valueThe code will return @True - 1 if LeaveHours is 100 and @False - 0 otherwise. You also need to enclose the date in square brackets.

Try

FIELD LeaveHours := @If(EndDate < [01/01/2007]; 100; LeaveHours)

Subject: RE: Compare Dates

Matt

That was it!

Thank You

Subject: RE: Compare Dates

What error message are you getting? I have had trouble with date fields in the past, and so I @Date everything so I know I’m comparing elements of the same data type.

Try @If(@Date(EndDate) < @Date(2007; 01; 01); Leavehours = 100; Leavehours)

Helen.

Subject: RE: Compare Dates

Then tinker with it more. I’m trying to teach you to fish. :slight_smile:

Subject: Compare Dates

You always need to be careful with dates because the format you use may NOT be the format someone else is using on their computer.

The field EndDate a Date/Time field or a Text field? (Saw your later response now - sorry)

If it’s a date time you should be able to just write (I like to use @date to just be clear in my code)

(Not sure why you have leavehour=100 - was this mean to be an assignment?)

LeaveHours := @if(EndDate < @date(2007;01;01); 100; LeaveHours);