Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate Odd/even days?

Status
Not open for further replies.

3Mark3

Technical User
Nov 30, 2005
48
US
Hello all....I can't seem to find a way to query Odd or even days.

I'm working with a date field....although I imagine it would work with a number as well...


Could anyone help me?

Thank you!


Mark
 
For EVENs
Code:
Where Day([SomeDateField]) Mod 2 = 0
and for ODDs
Code:
Where Day([SomeDateField]) Mod 2 = 1
 
yes, but ... then odd / even for what "Day"?

[tab]Day of the Week (alais WeekDay)

[tab][tab]Day of the month

[tab][tab][tab]Day of the year

[tab][tab][tab][tab]Day of ... (some other interval)

I know it must seem like I'm belaboring the poit, but the BRIEF function below and the results illustrate all to well that the question begs the question. If I can get different answers from teh same date depending on the interval selected (even amongst the three trivial examples) doesn't it make sense to clarify the question before providing the snap to judgement answer?

Code:
? basEvenOddDate(DAte(), "Week")
False

? basEvenOddDate(DAte(), "Month")
True

? basEvenOddDate(DAte(), "Year")
False



? DAte
6/13/2006

Code:
Public Function basEvenOddDate(OddEvenDate As Date, Interval As String) As Boolean

    'Return a flag to denot the eveness of a date within an interval

    Select Case Interval
        Case Is = "Week"
            basEvenOddDate = (Weekday(OddEvenDate) Mod 2 = 0)

        Case Is = "Month"
            basEvenOddDate = Day(Month(OddEvenDate) Mod 2 = 0)

        Case Is = "Year"
            basEvenOddDate = (DateDiff("d", DateSerial(Year(OddEvenDate), 1, 1), OddEvenDate) Mod 2 = 0)

    End Select
End Function

MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top