google analytics

meta

adsense

Tuesday, March 6, 2012

SQL to get the Next or previous Weekend Date - NEXT_DAY

The below SQL gives the next Saturday and the next Sunday dates.


SELECT NEXT_DAY('06-MAR-2012', 'SATURDAY') "next saturday" 
,NEXT_DAY('06-MAR-2012', 'SUNDAY') "next sunday"
FROM dual;






If the requirement is to find the previous weekend dates, just subtract the dates by 7.


SELECT NEXT_DAY('06-MAR-2012', 'SATURDAY')-7 "next saturday" 
,NEXT_DAY('06-MAR-2012', 'SUNDAY')-7 "next sunday" 
FROM dual;

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...