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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computing Leap Year

Status
Not open for further replies.

gwendon

Technical User
Apr 7, 2002
23
US
I have to track the date Doctor's special pay agreements expire. The formula I'm using in my query is very simple, but it does not account for Leap Years unless I go in and manually change the days from 365 to 364.
Is there a way to calculate the leap year into my formula?

SpecPayExp1Yr: IIf([SpecPayOneYrAgree]=No,"",[SpecPayStartDate]+365)
 
Hi

SpecPayExp1Yr: IIf([SpecPayOneYrAgree]=No,"",DateAdd("yyyy",1,[SpecPayStartDate])

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi

SpecPayExp1Yr: IIf([SpecPayOneYrAgree]=No,"",DateAdd("yyyy",1,[SpecPayStartDate]))

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
A somewhat more generic "method" to determine if a date falls within a leap year:

Code:
MyDate = Date
IsLpYr = IIF(DateDiff("d", "1/1/" & Year(MyDate), Year(MyDate) + 1) = 366, True, False)
? IsLpYr
False

MyDate = #1/1/1960#
IsLpYr = IIF(DateDiff("d", "1/1/" & Year(MyDate), "1/1/" & Year(MyDate) + 1) = 366, True, False)
? IsLpYr
True

MyDate = #1/1/2000#
IsLpYr = IIF(DateDiff("d", "1/1/" & Year(MyDate), "1/1/" & Year(MyDate) + 1) = 366, True, False)
? IsLpYr
True

MyDate = #1/1/1900#
IsLpYr = IIF(DateDiff("d", "1/1/" & Year(MyDate), "1/1/" & Year(MyDate) + 1) = 366, True, False)
? IsLpYr
False
[code]

Of course, the datediff expression -by itself- may be used in place of your constant:

[code]
MyDays = DateDiff("d", "1/1/" & Year(MyDate), "1/1/" & Year(MyDate) + 1)

SpecPayExp1Yr: IIf([SpecPayOneYrAgree]=No,"",[SpecPayStartDate]+MyDays)




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thank you very much for your help!! My problem is now solved.
Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top