要求:第一天的时间00:00:00
和最后一天的时间23:59:59
代码:
SELECT
date_trunc( 'month', CURRENT_DATE ) :: TIMESTAMP AS first_timestamp,
date_trunc( 'month', CURRENT_DATE ) :: TIMESTAMP + INTERVAL '1 month - 1 second' AS last_timestamp;
实现效果:
查询本月数据条数:
SELECT count(*) as total from table WHERE login_time BETWEEN date_trunc('month', current_date)::timestamp AND date_trunc('month', current_date)::timestamp + interval '1 month - 1 second'
实现效果: