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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
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
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.

All Courses

From novice to tech pro — start learning today.