Need a SQL Function that get me the 2nd Saturday of the month

Database
Enthusiast

Need a SQL Function that get me the 2nd Saturday of the month

Hi,

I need an SQL Function that gets me the 2nd Saturday of the month.

if
(Function (CURRENT_DATE) DAY) = 'SATURDAY' --Here I want the 2nd saturday
do some extract.
then
some data extract;
else
EXTRACT_FROM_DT = CURRENT_DATE -7
fi

Thanks in Advance.
3 REPLIES
Enthusiast

Re: Need a SQL Function that get me the 2nd Saturday of the month

I think you can use Sys_calendar.Calendar for that.

Something like

SELECT 1 FROM Sys_Calendar.Calendar C
WHERE C.calendar_date = current_date
AND C.day_of_week = 7
AND C.day_of_month between 8 and 14

Re: Need a SQL Function that get me the 2nd Saturday of the month

--Get all second saturdays from sys_calendar.calendar

SELECT calendar_date
FROM Sys_Calendar.Calendar
WHERE day_of_week = 7
AND weekday_of_month = 2
Enthusiast

Re: Need a SQL Function that get me the 2nd Saturday of the month

Thanks joedsilva.

It solved my problem.