SQL计数天数,直到月初 [英] SQL Count days till first of the month
本文介绍了SQL计数天数,直到月初的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算从日期到下个月的第一天的日子
How would I count the days from a date till the first of the following month
示例:
--Start Date
07-07-2011
多少天直到:
-- The 1st of the succeeding month of the start date above
08-01-2011
预期结果(天):
25
所以如果我算一天得到25,所以运行这个查询得到我所需的时间戳:
So if I counted the day I get 25, so running this query gets me the desired timestamp:
SELECT CURRENT_DATE + INTERVAL '25 DAYS'
结果:
2011-08-01 00:00:00
只是想不到一种方式来获得天数,任何建议?
just can't think of a way to get the number of days, any suggestions?
或开始日期,结束日期,天数之间?
Or start date, end date, number of days between?
推荐答案
我没有PostgreSQL服务器,所以这是未经测试的,但我会尝试:
I don't have a PostgreSQL server handy, so this is untested, but I would try:
SELECT (DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 MONTH') - CURRENT_DATE
这篇关于SQL计数天数,直到月初的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文