PL/SQL Date Functions

This blog post discusses a package of useful date functions, written in PL/SQL.


View the package specification for instructions on how to call the following functions:

GitHub Repo
util_date package spec


util_date package body

View the package specification for instructions on how to call the following functions:


UTIL_DATE Functions
Function Name Description
count_day_of_week Returns count of occurences of a given weekday between 2 dates. e.g. count all Mondays in a 3 month period.
first_day Returns date of first day of the specified month, e.g. first_day(SYSDATE) returns date of first day in current month.
month_day_first Returns date of month on which the specified day first occurs, e.g. month_day_first(SYSDATE,5) returns date of first Friday in current month.
month_day_last Returns date of month on which the specified day last occurs, e.g. month_day_last(SYSDATE,5) returns date of last Friday in current month.
is_a_working_day Returns a boolean value TRUE if the date is a working day (not a holiday or weekend), otherwise FALSE.
first_workday_month Returns date of first working day in the month, excluding holidays and weekends.
last_workday_month Returns date of last working day in the month, excluding holidays and weekends.
working_days Returns a count of the number of working days within the specified date range, excluding holidays and weekends.
carnival_monday Returns the date of Carnival Monday.
shrove_tuesday Returns the date of Shrove Tuesday.
mardi_gras Returns the date of Mardi Gras.
ash_wednesday Returns the date of Ash Wednesday.
palm_sunday Returns the date of Palm Sunday.
good_friday Returns the date of Good Friday
easter_sunday Returns the date of Easter Sunday.
easter_monday Returns the date of Easter Monday.
easter_friday Returns the date of first Friday following Easter.
easter_saturday Returns the date of first Saturday following Easter.
ascension_day Returns the date of Ascension.
whitsun Returns the date of Whitsun (Pentecost).
whit_monday Returns the date of Whit Monday.
corpus_christi Returns the date of Corpus Christi.


easter_sunday

Easter Eggs

The function easter_sunday returns the date of Easter Sunday for a given year.


SELECT util_date.easter_sunday(2024) 
FROM dual;
31-MAR-24

Try it for yourself

ACCEPT p_year NUMBER FORMAT '9999' PROMPT 'Enter a year:';
SELECT 'Easter in ' || &p_year || 
       ' falls on: ' || 
        to_char(util_date.easter_sunday(&p_year),'Dy Mon DD YYYY')
FROM dual;
                








Previous Blog Next Blog