Mysql function to Check if an year is leap year or not

Posted: May 11, 2011 in computer, Tecnhology and IETE, Knowledge Base

Mysql function to Check if an year is leap year or not:

drop function if exists is_leapyear;
delimiter |
CREATE FUNCTION is_leapyear(y1 int(4))
RETURNS int(1)
begin
declare r int;
set r = case when (y1%4=0) then 1 else 0 end;
return r;
end|

Comments
  1. hans says:

    every 100 years its not a leap year but every 400 years it is a leap year again

  2. Marco says:

    I would like a function that calculate age in year.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s