Author |
Topic |
rauof_thameem
Starting Member
31 Posts |
Posted - 2007-05-15 : 23:51:59
|
Hi..,How do i can check for leap year in date |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-16 : 00:01:28
|
what is the input like ? just the year ? KH |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-16 : 00:27:06
|
[code]declare @d datetimeset @d='2100-01-01'Select case when year(@d)%400=0 then 'yes' when year(@d)%100=0 then 'no' when year(@d)%4=0 then 'yes' else 'no' end as is_leap_year[/code]MadhivananFailing to plan is Planning to fail |
|
|
rauof_thameem
Starting Member
31 Posts |
Posted - 2007-05-16 : 00:46:07
|
Thanks Mahadi |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-05-16 : 00:56:48
|
[code]select YEAR, IS_LEAP_YEAR = -- If 60th day of the year is in February, then it's leap year. case month(dateadd(yy,a.YEAR-1900,0)+59) when 2 then 'yes' else 'no' endfrom ( select YEAR = 1800 union all select YEAR = 1900 union all select YEAR = 2000 union all select YEAR = 2001 union all select YEAR = 2002 union all select YEAR = 2003 union all select YEAR = 2004 union all select YEAR = 2005 union all select YEAR = 2006 union all select YEAR = 2007 union all select YEAR = 2008 union all select YEAR = 2009 union all select YEAR = 2010 union all select YEAR = 2011 union all select YEAR = 2400 ) aResults:YEAR IS_LEAP_YEAR ----------- ------------ 1800 no1900 no2000 yes2001 no2002 no2003 no2004 yes2005 no2006 no2007 no2008 yes2009 no2010 no2011 no2400 yes(15 row(s) affected)[/code]CODO ERGO SUM |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-16 : 10:58:17
|
Good Logic. I knew you will come up with different logic MadhivananFailing to plan is Planning to fail |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-16 : 11:03:42
|
quote: Originally posted by rauof_thameem Thanks Mahadi
Check my name carefully MadhivananFailing to plan is Planning to fail |
|
|
anki0121
Starting Member
1 Post |
Posted - 2009-04-03 : 04:06:48
|
This is very simple....select (case to_number(to_char((trunc(to_date('15/08/08','dd/mm/yy'),'yy')+59),'mm')) when 2 then 'Yes' else 'No' end) as yrfrom dualhere I have first found the first day of the year which can be done by usingSelect Trunc(To_date(SYSDATE),'yy')from dualand then adding 59 days to it and then using the case statement to check whether the month is 2 or 3 depending on which leap year can be found outWhen u need someone... Ankeyzzzz always dere |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-03 : 05:08:58
|
quote: Originally posted by anki0121 This is very simple....select (case to_number(to_char((trunc(to_date('15/08/08','dd/mm/yy'),'yy')+59),'mm')) when 2 then 'Yes' else 'No' end) as yrfrom dualhere I have first found the first day of the year which can be done by usingSelect Trunc(To_date(SYSDATE),'yy')from dualand then adding 59 days to it and then using the case statement to check whether the month is 2 or 3 depending on which leap year can be found outWhen u need someone... Ankeyzzzz always dere
Are you aware that this site is specific to MS SQL Server?MadhivananFailing to plan is Planning to fail |
|
|
|