PostgreSQL的日期運算計算函數使用

來源:互聯網
上載者:User

PostgreSQL的日期運算計算函數使用

PostgreSQL的日期運算計算函數使用

一:各個資料中的串連符

SqlServer的串連符:+(加號)

Sqlite的串連符:.(點)

PostgreSQL的串連符:||(或)

二:

今天在PostgreSQL計算日期的時候,翻了一些資料,很少,就記錄下來吧~!

其中使用到的函數及變數

to_char()、Date()、now()、current_date

計算兩個日期的差

current_date為今天的日期,為:2015-06-03


Date('2015-06-05')-current_date=2

select  to_char(current_date,'yyyy')||'-'||to_char(birthday,'mm-dd'),Date(to_char(current_date,'yyyy')||'-'||to_char(birthday,'mm-dd'))-current_date

from tablename where delflag=0 and status=0

and Date(to_char(current_date,'yyyy')||'-'||to_char(birthday,'mm-dd'))-current_date>=0

and Date(to_char(current_date,'yyyy')||'-'||to_char(birthday,'mm-dd'))-current_date<=7 order by birthday desc

三:


select now() + interval '1 days'; select now() + interval '1 month'; select now() + interval '1 years'; 四:SqlServer中進行日期計算時,用到函數CONVERT(),DATEPART(),getDate()
select CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+'-'+ CONVERT(varchar(2),DATEPART(month,birthday))+'-'+CONVERT(varchar(2),DATEPART(day,birthday)),120),datediff(day,CONVERT(varchar(10),getdate(),120),CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+'-'+ CONVERT(varchar(2),DATEPART(month,birthday))+'-'+CONVERT(varchar(2),DATEPART(day,birthday)),120)) from tablename where delflag=0 and status=0 and datediff(day,CONVERT(varchar(10),getdate(),120),CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+'-'+ CONVERT(varchar(2),DATEPART(month,birthday))+'-'+CONVERT(varchar(2),DATEPART(day,birthday)),120))<=7 and datediff(day,CONVERT(varchar(10),getdate(),120),CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+'-'+ CONVERT(varchar(2),DATEPART(month,birthday))+'-'+CONVERT(varchar(2),DATEPART(day,birthday)),120))>=0 order by birthday desc

------------------------------------華麗麗的分割線------------------------------------

CentOS 6.3環境下yum安裝PostgreSQL 9.3

PostgreSQL緩衝詳述

Windows平台編譯 PostgreSQL

Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)環境的配置與安裝

Ubuntu上的phppgAdmin安裝及配置

CentOS平台下安裝PostgreSQL9.3

PostgreSQL配置Streaming Replication叢集

如何在CentOS 7/6.5/6.4 下安裝PostgreSQL 9.3 與 phpPgAdmin 

------------------------------------華麗麗的分割線------------------------------------

PostgreSQL 的詳細介紹:請點這裡
PostgreSQL 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.