Leap or not

D

Douglas J. Steele

If(Day(DateSerial(WhatYear, 3, 0)) = 29
' It's a leap year
Else
' It's not a leap year
End If
 
F

fredg

Hi

How can I check from a given year if feb has 28 days or 29?

Thanks

Regards

In what context? When? Where? Why?
If you attempt to enter a date of 2/29/someyear Access will not accept
it if it is not a leap year. that should tell you right there.

However...
Here is a function you can use.
Copy and paste it into a module.

Function IsLeapYear() as String
On Error GoTo Err_Handler
Dim strYear As String
strYear = InputBox("Enter the year to be checked.", , Year(Date))
strYear = "2/29/" & strYear
Dim dteDate As Date
dteDate = CDate(strYear)

IsLeapYear = "It is a leap year."

Exit_Function:
Exit Function:

Err_Handler:
IsLeapYear = "It's NOT a leap year."
Resume Exit_Function
End Function

You can call it from the Debug window using
? IsLeapYear()
from any code window using =IsLeapYear(), or change the entry of the
year by adapting this function to your specific needs.
 
T

Tom van Stiphout

On Mon, 24 Mar 2008 17:31:21 -0000, "John" <[email protected]>
wrote:

Free after Kernighan and Richie, 1978, what is in my mind one of the
most beautiful one-liners in programming:

Function IsLeap(ByVal intYear As Integer) As Boolean
IsLeap = intYear Mod 4 = 0 And intYear Mod 100 <> 0 Or intYear Mod
400 = 0
End Function

IOW: it's a leap year if the year is evenly divisible by 4, except if
it is evenly divisible by 100, except if it is evenly divisible by
400.

-Tom.
 
Top