Calculated field to capture +/- 28 days from date

  • Hello

    I need to create a calculated field that will give me 'yes' or 'no' if a date field is within +/- 28 days of another date field. So for example if a.date = 1/1/15 and b.date is 30/3/15 the calculated field will say 'no'; if the b.date was 10/1/15 it would say yes. Similarly, if the b.date was 1/11/14 it would say 'no'; if it was 10/12/14 it would say 'yes'.

    I appreciate I will need to write an IIF statement, probably nested, but am struggling with this, so any suggestions would be very welcome.

    Thanks

  • Sorry, didn't read very carefully...

    I think this will do what you want... or most of it.

    DECLARE @Date1 DATE = '10-Aug-2015',

    @Date2 DATE = '07-Sep-2015'

    ,@Diff INT

    SELECT @Diff = ABS(DATEDIFF(day,@Date1,@Date2));

    PRINT @Diff;

    the ABS() removes the sign...

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply