3 Replies Latest reply on Mar 10, 2011 12:33 PM by philmodjunk

# Calculation --> If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

### Title

Calculation --> If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

### Post

I need to write a calculation that does the following:

If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

Where if the current date is within 2 weeks of the DateField, the result will = 1, otherwise it will be 0.

--

How do I express the "within 2 weeks of " specifically?

I tried:

If (Get (Current Date) < (DateField - 14)); 0; 1

But it didn't work.  I don't think "14" is the way to express the two weeks in this case.

---

thanks!

Eric V

• ###### 1. Re: Calculation --> If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

Depends on your definition of "within 2 weeks"

If ( get ( CurrentDate ) < ( datefield - 14 ) ; 1 ; 0 )

Should return 1 for all dates where datefield is either in the past or no more than 14 days in the future.

It can be simplified to just: get ( CurrentDate ) < ( datefield - 14 )

And if this is defined for a field, it must be an unstored field of type calculation or it won't update as the current date changes.

• ###### 2. Re: Calculation --> If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

Thanks Phil,

Ok, so it sounds like "14" is the way to define two weeks in this case.  Thanks.

I'm not sure I follow you with the simplified version.  It looks the same... Are you saying this shouldn't be an IF function?

It might help to define further what I'm trying to do:

I want an Field_ALERT to turn red if CurrentDate is within 2 weeks of separate DateField.

Currently, Field_ALERT is a calc field with the above IF calculation.

I have Field_ALERT conditionally formatted to turn red if Field_ALERT = 1

Let me know if I'm going about this the wrong way.  Thanks!

• ###### 3. Re: Calculation --> If (Get (Current Date) is within 2 weeks of  DateField); result 1; result 2

Just to get values of 1 or 0 you do not need the If function.

Boolean expressions that are true return 1 and False return 0 so using the IF funciton isn't needed here.

Your conditional format expression can be simplified the same way to jsut read: field_ALERT.

(I use the IF function anyway sometimes as it just seems a bit less cryptic to me, but that's solely a personal preference.)