如何在postgresql中使用它?
SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())发布于 2020-07-07 12:01:02
您可以使用current_date和date_part;
postgres=# select date_part('month', current_date) as month,
date_part('year', current_date) as year;
month | year
-------+------
7 | 2020
(1 row)发布于 2020-07-07 11:57:27
使用CURRENT_TIMESTAMP并提取月份。
select EXTRACT(month from CURRENT_TIMESTAMP);发布于 2020-07-07 13:37:25
最简单的解决方案可能是
SELECT * FROM atable
WHERE date_trunc('month', columnname) = date_trunc('month', current_timestamp);该函数将时间戳向下舍入到指定的精度,在本例中为月初。
https://stackoverflow.com/questions/62767868
复制相似问题