如何在postgres sql查询中获取当前月份firstdate和lastdate

sur*_*esh 1 postgresql date sql-date-functions timestamp-with-timezone

我想获得当月的第一个和最后一个日期(如30日或31日).如何通过使用postgress sql查询获得此日期.

Eva*_*oll 6

第一天很容易......

SELECT date_trunc('month', CURRENT_DATE);
Run Code Online (Sandbox Code Playgroud)

最后一天也不是那么困难.

SELECT date_trunc('month', CURRENT_DATE) + interval '1 month - 1 day';
Run Code Online (Sandbox Code Playgroud)