Select first day of preceding month in (DB2) SQL


0 Answers

First Day of the Current Month:

CURRENT_DATE - (DAY(CURRENT_DATE)-1) DAYS 

First of the Current Year is

CURRENT_DATE - (DAY(CURRENT_DATE)-1) DAYS - (MONTH(CURRENT_DATE)-1) MONTHS 

Last Day of the Last Month:

CURRENT_DATE - DAY(CURRENT_DATE) DAYS 

First Day of the Last Month:

CURRENT_DATE - (DAY(CURRENT_DATE)-1) DAYS - 1 MONTH 
Question

I need to check whether a given date is in the preceding month for a monthly query. I can get

CURRENT DATE - 1 MONTH

to compare the selected date with, but I can't assume the current date will be the first day of each month exactly. Is there a built in way to get the first day of the month without extracting the year and month and gluing it back together?




Related



Tags