Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
hey i want to know how to check Leap Year when user enter a Year.
i have no idea about it which logic i will use to solve it. please help me.
Thanks in Advance :)
Posted
Updated 19-Oct-10 18:02pm
v2

you can check leap year by using given logic.

MIDL
if((year % 4 ==0)&&(year % 100 != 0 || year % 400==0))
{
// yes year is leap year
}
else
{
//No year is not a Leap Year

}
 
Share this answer
 
The following method returns "true" if the given year is a leap year and "false" if not.

System.DateTime.IsLeapYear(here give year)


Hope this helps!

Added custom written logic:

C#
private bool IsLeapYear(int yearNumber)
{
  if ((yearNumber % 400) == 0)
    return true;
  else if ((yearNumber % 100) == 0)
    return false;
  else if ((yearNumber % 4) == 0)
    return true;
  else
    return false;
}


But you really should use the build in logic of the .Net Framework!!
 
Share this answer
 
v4
Comments
ShilpaKumari 20-Oct-10 0:09am    
Thanks for your answer but it is Predefined.
i am searching own logic by which i can find Leap Year
ShilpaKumari 20-Oct-10 0:16am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900