簡體   English   中英

PostgreSQL中兩個日期之間的差異

[英]The difference between the two dates in PostgreSQL

PostgreSQL中有與此T-SQL命令等效的命令嗎?

SELECT COUNT(*) 
FROM [dbo].[LayerTable] 
where layerType=3 
 and created >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -6, current_timestamp))),0)

我發現date_part()和提取function(),但不能正常工作。

看起來這只是從current_timestamp中減去6個月,因此等效為:

SELECT COUNT(*) 
FROM dbo.layer_table
where layer_type=3 
  and created >= current_timestamp - interval '6 months';

如果希望將月初(而不是“今天”與“今天”)作為結果,請使用:

created >= date_trunc('month', current_timestamp - interval '6 months')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM