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 acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > General Technology > Tech Tips & Tricks >
Check for a leap year in VB

Reply  
Thread Tools
Aftab's Avatar
Member with 80 posts.
 
Join Date: Oct 2003
22-Mar-2004, 06: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
Senior Member with 4,318 posts.
 
Join Date: Mar 2000
Location: Central Pennsylvania
Experience: Advanced
22-Mar-2004, 07: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 80 posts.
 
Join Date: Oct 2003
23-Mar-2004, 11: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
Senior Member with 4,318 posts.
 
Join Date: Mar 2000
Location: Central Pennsylvania
Experience: Advanced
23-Mar-2004, 01: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 80 posts.
 
Join Date: Oct 2003
24-Mar-2004, 06: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 80 posts.
 
Join Date: Oct 2003
24-Mar-2004, 06: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,285 posts.
 
Join Date: Nov 2003
Location: Oklahoma/Missouri(school)
Experience: learning, best with hardware
24-Mar-2004, 11:42 PM #7
why can't it be divisible by 100?
SIR****TMG's Avatar
Computer Specs
Distinguished Member with 47,676 posts.
 
Join Date: Aug 2003
Location: Corn Fields of OHIO
Experience: Einstein Jr. Indeed
25-Mar-2004, 12:14 AM #8
ALL THIS GAVE ME A HEAD ACHE
Aftab's Avatar
Member with 80 posts.
 
Join Date: Oct 2003
25-Mar-2004, 06: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,285 posts.
 
Join Date: Nov 2003
Location: Oklahoma/Missouri(school)
Experience: learning, best with hardware
25-Mar-2004, 09:06 PM #10
i think so.
Big-K's Avatar
Distinguished Member with 6,954 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
25-Mar-2004, 10: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, 10: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, 01: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, 01: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 80 posts.
 
Join Date: Oct 2003
30-Mar-2004, 04: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.
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:26 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.