Search code examples
sqldatehsqldb

Get first day of last month in Java HSQL database


How can I select first day of last month and last day of next month in HSQL database?

I tried it postgres way like follows:

SELECT date_trunc('month', current_date - INTERVAL '1 month') :: DATE AS first_day_of_last_month;

Does not work in Java HSQL database thou. :(


Solution

  • Use the LAST_DAY(date) function.

    LAST_DAY(CURRENT_DATE - 2 MONTH) + 1 DAY
    
    LAST_DAY(CURRENT_DATE + 1 MONTH)