PL/SQL – Find the first and last day of the month

I have always used the Financial / Manufacturing Calendar as setup in Oracle ERP, extracted into a Date Dimension. The query below calculated the First and Last of a month outside of the Financial Calendar.

There is an inbuilt function called LAST_DAY that calculated the last date of the provided date. The first day however can be achieved thru a Format as shown below.

SELECT TRUNC (SYSDATE, ‘MM’) AS start_date,
TRUNC (LAST_DAY (SYSDATE)) AS end_date
FROM DUAL

Advertisements

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: