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
pdvsaProject financeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)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
pdvsaProject 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
PatHartmanCommented:
Please post your code.  Did you substitute your own field names?

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Rey Obrero (Capricorn1)Commented:
missing ")"


if abs(DateDiff("d",dateserial(year([datefield]),month([datefield]),day([datefield])), dateserial(year([datefield]),1,15))) > 30 or
0
Gustav BrockCIOCommented:
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
    ' [Field1] is bad.
End If

/gustav
0
pdvsaProject 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
pdvsaProject financeAuthor Commented:
Gustav,

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

error
0
Gustav BrockCIOCommented:
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
     ' [Field1] is bad.
 End If

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.