Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Tech Tips & Tricks
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor ram recovery router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > General Technology > Tech Tips & Tricks >
Check for a leap year in VB

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
22-Mar-2004, 05:00 PM #1
Check for a leap year in VB
A quick way to check if a year is a leap year

public function IsLeap(Year as integer) as boolean
IsLeap = Isdate("29/02/" & Year)
end function
n2gun's Avatar
Distinguished Member with 4,312 posts.
 
Join Date: Mar 2000
Location: Central Pennsylvania
Experience: Advanced
22-Mar-2004, 06:16 PM #2
Another simple way is divide the year by 4. If it comes out without a remainder it is a leap year.
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
23-Mar-2004, 10:24 AM #3
calculating Leap year
Its not as simple as just dividing the year by 4, the actual logic for a leap year is:
year is divisible by 4, but NOT by 100 OR year is divisible by 400.
n2gun's Avatar
Distinguished Member with 4,312 posts.
 
Join Date: Mar 2000
Location: Central Pennsylvania
Experience: Advanced
23-Mar-2004, 12:26 PM #4
Re: calculating Leap year
Quote:
Originally posted by Aftab:
Its not as simple as just dividing the year by 4, the actual logic for a leap year is:
year is divisible by 4, but NOT by 100 OR year is divisible by 400.
DUH I don't see where I said anything about 100 or 400. Could you show where I did ?
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
24-Mar-2004, 05:03 AM #5
Calculating Leap Year
Quote:
DUH I don't see where I said anything about 100 or 400. Could you show where I did ?
You have misunderstood what I said. I was pointing out the actual logic of calculating a leap year, I was not trying to say that you had said anything about dividing by 100 and 400. This is what I was trying to get across: A year is a leap year IF the year is divisible by 4 AND 100, OR is divisible by 400.
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
24-Mar-2004, 05:05 AM #6
Leap Year
Sorry, slight error in last reply, logic is divisible by 4 but NOT divisible by 100 OR divisible by 400.
dannyboyfx's Avatar
Senior Member with 1,282 posts.
 
Join Date: Nov 2003
Location: Oklahoma/Missouri(school)
Experience: learning, best with hardware
24-Mar-2004, 10:42 PM #7
why can't it be divisible by 100?
SIR****TMG's Avatar
Computer Specs
Distinguished Member with 37,126 posts.
 
Join Date: Aug 2003
Location: Corn Fields of OHIO
Experience: Einstein Jr. Indeed
24-Mar-2004, 11:14 PM #8
ALL THIS GAVE ME A HEAD ACHE
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
25-Mar-2004, 05:17 AM #9
Leap Years
Quote:
why can't it be divisible by 100?
The reason it can't be divisible by 100 is because then we would have a leap year every 100 years (century years) as well as every 4 years. This would result in too many extra days being added, about 3 days every 400 years I think. Hope this makes sense.
dannyboyfx's Avatar
Senior Member with 1,282 posts.
 
Join Date: Nov 2003
Location: Oklahoma/Missouri(school)
Experience: learning, best with hardware
25-Mar-2004, 08:06 PM #10
i think so.
Big-K's Avatar
Distinguished Member with 6,940 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
25-Mar-2004, 09:08 PM #11
They explained all of that in an article in the Kansas City Star a few weeks ago. Pretty weird stuff it is.
Alfie_UK's Avatar
Senior Member with 1,263 posts.
 
Join Date: Mar 2003
Location: 10 mins from Tower of London/England
25-Mar-2004, 09:23 PM #12
Quote:
Originally posted by SIR****TMG:
ALL THIS GAVE ME A HEAD ACHE
Same here,just took couple of paracetamols
-Sx-'s Avatar
Junior Member with 24 posts.
 
Join Date: Mar 2004
Location: Planet Earth
28-Mar-2004, 12:52 AM #13
I suppose no one *really* uses the Internet anymore

How about this site:
http://www.codetoad.com/vb_leap_year.asp

Any year divisible by 400 will be divisible by 100 as well as 4. The operative function is If divisible by 4 cannot be divisible by 100 - so 2004 is a Leap Year.
2000 is a special case because it was divisble by all three...

( BTW - we do have leap years *every* 100 years
-Sx-'s Avatar
Junior Member with 24 posts.
 
Join Date: Mar 2004
Location: Planet Earth
28-Mar-2004, 12:58 AM #14
Grrr ... I take that last part back - we are entering aperiod where leaps years at the century mark are occuring less often:

$year = 100;
while(1) {
system("cal 2 $year");
sleep 1;
$year+=100;
}

Prior to 1800 every century was a leap year...

Sorry/Bill
Aftab's Avatar
Member with 72 posts.
 
Join Date: Oct 2003
30-Mar-2004, 03:26 PM #15
Leap years
Sorry if I didn't make that clear:
A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 08:51 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.