Tuesday, September 9, 2008

Determining Leap Year in Oracle and Days in February

Recently, I was playing around with a leap year issue and the number of days in February. I would like to share the following snippets of commands to help some people save some time.

--2 ways to determine if it is a LEAP YEAR in ORACLE

SELECT 2008 , Decode( mod(2008, 4), 0, decode( mod(2008, 400), 0, 'Yes', decode( mod(2008, 100), 0, 'No', 'Yes') ), 'No' ) as LEAP_YEAR
FROM DUAL;

or

SELECT DECODE(29, (SELECT to_date('01032008', 'DDMMYYYY') - to_date('01022008', 'DDMMYYYY')FROM DUAL),'LEAPYEAR','NOTLEAPYEAR')
FROM DUAL;

--2 ways to determine the NUMBER OF DAYS IN FEBRUARY in ORACLE

SELECT (EXTRACT (DAY FROM LAST_DAY(ADD_MONTHS(TRUNC(TO_DATE('2008','YYYY'),'YYYY'),1))))
FROM DUAL;

or

SELECT to_date('01032008', 'DDMMYYYY') - to_date('01022008', 'DDMMYYYY')
FROM DUAL;



Of course the input to these queries requires the year that you are inquiring about.

12 comments:

Anonymous said...

Bravo, what phrase..., an excellent idea

Anonymous said...

Nice brief and this mail helped me alot in my college assignement. Thank you seeking your information.

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now. Keep it up!
And according to this article, I totally agree with your opinion, but only this time! :)

Anonymous said...

i truly adore all your posting way, very interesting.
don't quit as well as keep penning mainly because it simply just well worth to look through it,
looking forward to view alot more of your own well written articles, regards!

Anonymous said...

Hello, i believe that i saw you visited my weblog so
i got here to return the favor?.I am attempting to to find issues to improve my web site!
I suppose its adequate to use some of your concepts!
!
My webpage - Zulily coupon code

Anonymous said...

I am regular visitor, how are you everybody? This paragraph
posted at this website is genuinely nice.

Feel free to visit my web-site - Villa Schoensinn Karlsruhe

Anonymous said...

I've been browsing online more than 3 hours today, yet I never found any interesting article like yours. It's pretty worth
enough for me. Personally, if all website owners and bloggers made good content
as you did, the web will be much more useful than ever before.


Here is my web-site california casualty auto and home insurance

Anonymous said...

I do not drop a comment, however after looking at through a
few of the comments here "Determining Leap Year in Oracle and Days in February".
I actually do have some questions for you if it's allright. Could it be simply me or does it seem like a few of the responses look as if they are written by brain dead individuals? :-P And, if you are posting on additional sites, I'd like to follow you.
Could you make a list of all of all your public pages like
your Facebook page, twitter feed, or linkedin profile?

Also visit my website - canadian online casino
My web page - canadian online casino

Anonymous said...

I usually do not comment, but I read a ton of responses
on "Determining Leap Year in Oracle and Days in February".
I actually do have 2 questions for you if you tend
not to mind. Could it be simply me or do some of the responses appear as if they are left by brain dead folks?
:-P And, if you are posting on other social sites, I would like to follow you.
Would you list of every one of all your social community sites like your Facebook page, twitter feed, or linkedin profile?


Have a look at my site - Graduate Quarterly

Anonymous said...

At this time I am ready to do my breakfast, once having my breakfast coming over again to read further news.


Stop by my web-site - Arabic Books

Anonymous said...

I am not sure where you are getting your information, but great topic.
I needs to spend some time learning more or understanding more.
Thanks for great information I was looking for this info for my mission.


my blog post: public sex for cash

Anonymous said...

You're so interesting! I don't think I have read
something like that before. So wonderful to find somebody
with original thoughts on this issue. Really.. thanks for starting this up.
This web site is something that is required on the web, someone with
a little originality!

Feel free to surf to my web blog http://www.cfnmfever.net/