Determine if Leap Year

  • Thread starter Thread starter cp2599
  • Start date Start date
C

cp2599

I need to know how to tell if an entered year is a leap year so that I
know whether to concatenate an 02/28/ or an 02/29/ to the end of the
month date. Any ideas?

I know leap years have to be evenly divisible by 4 but don't know how
to check the remainder. I also think there's another piece to the
equation to prevent years like 2000 from being included, but can't
remember the formula.
 
I need to know how to tell if an entered year is a leap year so that I
know whether to concatenate an 02/28/ or an 02/29/ to the end of the
month date. Any ideas?

I know leap years have to be evenly divisible by 4 but don't know how
to check the remainder. I also think there's another piece to the
equation to prevent years like 2000 from being included, but can't
remember the formula.

You really don't need to know if any particular year is a leap year.
Access knows.
One way to find out is to set a date datatype field to 2/29/Year on
your data entry form.
If that date is not a valid date, Access will give you an error. Trap
the error and reset the date to 2/28/Year.

You could also set a control to
=DateSerial(TheYear,3,0)
which will return either 2/28/year or 2/29/year, depending upon
whether that year is a leap year.
 
Not quite. For example, 1900 wasn't a leap year, nor will 2100 be one, yet
they're both divisible by 4.

IIf(Day(DateSerial(Year(Date()), 3, 0)) = 29, "Leap Year", "Not Leap Year")
 
You really don't need to know if any particular year is a leap year.
Access knows.
One way to find out is to set a date datatype field to 2/29/Year on
your data entry form.
If that date is not a valid date, Access will give you an error. Trap
the error and reset the date to 2/28/Year.

You could also set a control to
=DateSerial(TheYear,3,0)
which will return either 2/28/year or 2/29/year, depending upon
whether that year is a leap year.

What do you mean by trapping the error?
 
   IIF(Year(Date()) Mod 4 >0, "Leap Year", "Not Leap Year")
--
Build a little, test a little.






- Show quoted text -

Thank you ... do you know the second half of the leap year edit?
 
Thank you ... do you know the second half of the leap year edit?

Re: "do you know the second half of the leap year edit"
What do you mean by that part?

Perhaps this ... If Year is divisible by 4 or if a Century Year is
divisible by 400 (without a remainder) it is a leap year.

1996/4 = 499 (Leap Year
1998/4 = 499.5 (Not a leap year)
Or Century years
1900/400 = 4.75 (Not a leap year)
2000/400 = 5 (Leap Year)
2100/400=5.25 (Not a leap year)
 
What do you mean by trapping the error?


Look up "Error Trapping" in VBA help.
For example, entering an invalid date in a Date datatype control on a
form raises error #2113.
You can trap that error in the code's Error Handling.
 
Not quite. For example, 1900 wasn't a leap year, nor will 2100 be one, yet
they're both divisible by 4.

IIf(Day(DateSerial(Year(Date()), 3, 0)) = 29, "Leap Year", "Not Leap Year")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)







- Show quoted text -

The DateSerial function returns 2/28/2009 which is correct, but the
Day function returns 30 instead of 28. Any ideas as to why?
IIF (Day(DateSerial(Me.dtmYear,3,0)) = 29, "Leap Year", "No Leap Year"
 
Look up "Error Trapping" in VBA help.
For example, entering an invalid date in a Date datatype control on a
form raises error #2113.
You can trap that error in the code's Error Handling.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail- Hide quoted text -

- Show quoted text -

Thank you.
 
Re: "do you know the second half of the leap year edit"
What do you mean by that part?

Perhaps this ... If Year is divisible by 4 or if a Century Year is
divisible by 400 (without a remainder) it is a leap year.

1996/4 = 499 (Leap Year
1998/4 = 499.5 (Not a leap year)
Or Century years
1900/400 = 4.75 (Not a leap year)
2000/400 = 5 (Leap Year)
2100/400=5.25 (Not a leap year)
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail- Hide quoted text -

- Show quoted text -

Thank you
 
Not quite. For example, 1900 wasn't a leap year, nor will 2100 be one, yet
they're both divisible by 4.

IIf(Day(DateSerial(Year(Date()), 3, 0)) = 29, "Leap Year", "Not Leap Year")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)







- Show quoted text -

Just used the DateSerial function to get the end date I'm looking
for. Thanks.
 
IIF(Year(Date()) Mod 4 >0, "Leap Year", "Not Leap Year")

Try it for 1900. That wasn't a leap year. 2100 won't be either!

OK, I know this won't come up in most apps... just being a smartass.
 
Back
Top