如何在知道事件日期的情况下找出一周的开始和结束日期。
DATEADD(dd, -(DATEPART(dw, eventDate)-1), eventDate) [WeekStart]
DATEADD(dd, 7-(DATEPART(dw, eventDate)), eventDate) [WeekEnd]
我试过这种方法,但它给出了错误
ERROR: function datepart(unknown, timestamp without time zone) does not exist
LINE 3: DATEADD('dd', -(DATEPART('dw', eventDate)-1)
你能建议 postgres 的查询是什么吗?
在 Postgres 中,只需使用date_trunc()
:
select date_trunc('week', eventDate),
date_trunc('week', eventDate) + interval '1 week'
您的代码是 SQL Server 语法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句