jump to navigation

find 3rd or Third saturday falling on which date in any month July 23, 2010

Posted by sendtoshailesh in Uncategorized.
trackback

One of my colleage was struggling to crack the code to find on which date 3rd saturday falls for any month. He tried very well for a code but I took this as a tricky problem. I tried couple of options and finally reached to better solution. at the end I found it is pretty simple———

select next_day(to_date(’01’||to_char(to_date(‘&input_MMYYYY’,’MM-YYYY’),’MON-YYYY’)),’sat’)+14 from dual;

enjoy….

Advertisements

Comments»

1. Sheila GA - June 14, 2012

Thank you very much. I’m working on db2 and here is the query to figure out 3rd Saturday in db2:

db2 “select next_day(date(substr(char(current date – 1 month ),7,4)||’-‘|| substr(char(current date – 1 month),1,2)||’-01′)+ 14 days,’SAT’) as saturday3rd from sysibm.sysdummy1 ”

SATURDAY3RD
———–
05/19/2012

Thanks.

Sheila

sendtoshailesh - June 15, 2012

Thanks Sheila, This would be helpful..

2. Sheila GA - June 20, 2012

Sorry the query I entered with current date – 1 month will find the 3rd Saturday of last month.

Just want to clarify.

Thanks.

Sheila


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

%d bloggers like this: