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