# January 15 and July 15, not within 30 days of these dates

Hello,

I have a technical criteria.

How can I verify that a date is not within 30 days of each January 15 and July 15?   This would be extended out many years so I the year can not be hard coded.  This might be more simply than I think.   Field names are not impt...if need to ref a field name just make it as Field1, Field2

thank you
###### Who is Participating?

CIOCommented:
Yes, you need it on one line or append a line continuation character: _

If Abs(DateDiff("d", DateAdd("m", 6, [Field1]), DateSerial(Year([Field1]), 7, 15))) > 30 And _
Abs(DateDiff("d", [Field1], DateSerial(Year([Field1]), 7, 15))) > 30 Then
' [Field1] is good.
Else
End If

/gustav
0

Commented:
try this, [datefield] is the field that contains your dates.

if abs(DateDiff("d",dateserial(year([datefield]),month([datefield]),day([datefield])), dateserial(year([datefield]),1,15)) > 30 or
abs(DateDiff("d",dateserial(year([datefield]),month([datefield]),day([datefield])), dateserial(year([datefield]),7,15)) > 30  then
0

Project financeAuthor Commented:
Rey, I get a compile error on the word "abs". The error says "Expected Identifier".  The entire line is red.

let me know what you think...
0

Commented:

Rey, I think the January test needs to be two tests.  One for the current year as you have it and also one for the prior year to pick up dates in December.
0

Commented:
missing ")"

if abs(DateDiff("d",dateserial(year([datefield]),month([datefield]),day([datefield])), dateserial(year([datefield]),1,15))) > 30 or
0

CIOCommented:
If you shift the date to test six month so the interval to avoid falls within the same month/year, it can be simplified to:

If Abs(DateDiff("d", DateAdd("m", 6, [Field1]), DateSerial(Year([Field1]), 7, 15))) > 30 And
Abs(DateDiff("d", [Field1], DateSerial(Year([Field1]), 7, 15))) > 30 Then
' [Field1] is good.
Else
End If

/gustav
0

Project financeAuthor Commented:
Rey, OK I copied and pasted the above with the missing parenth  but still have an error.

this is how I have it with the parenth: (it is all in red)
if abs(DateDiff("d",dateserial(year([datefield]),month([datefield]),day([datefield])), dateserial(year([datefield]),1,15))) > 30 or
abs(DateDiff("d",dateserial(year([txtRequestedDisbDate]),month([txtRequestedDisbDate]),day([txtRequestedDisbDate])), dateserial(year([txtRequestedDisbDate]),7,15)) > 30  then

Also, I don't need to test in the past.  Its only future.
0

Project financeAuthor Commented:
Gustav,

thanks...however it is red upon a copy and paste as well.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.