時間:2024-02-03 17:42作者:下載吧人氣:17
按照給定格式返回:to_char(timestamp,format)
返回相差的天數:(date(time1) – current_date)
返回時間戳對應的的日期[yyyy-MM-dd]:date(timestamp)
計算結果取兩位小數(方便條件篩選):round((ABS(a-b)::numeric / a), 2) * 100 < 10
加減運算
‘-‘ :前x天/月/年
‘+’ :后x天/月/年
current_timestamp – interval ‘x day/month/year…’ 返回時間戳
date_part(‘day’, current_timestamp – time1) 兩個時間相差的天數
返回時間間隔的秒數
兩個timestamp 直接相減返回的是 interval類型,而不是毫秒數
extract(epoch from (time1- time2)) * 1000
如果在sql 中使用long類型的 timestamp,需要包裹 to_timestamp() 函數
參考資料:
1. https://www.yiibai.com/manual/postgresql/functions-formatting.html
2. http://www.postgres.cn/docs/9.4/functions-datetime.html
到此這篇關于教你postgresql 中的如何時間處理小技巧的文章就介紹到這了,更多相關postgresql 時間處理內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!
網友評論