Home > Database > Mysql Tutorial > PostgreSQL的日期运算计算函数使用

PostgreSQL的日期运算计算函数使用

PHPz
Release: 2018-09-30 14:14:03
Original
1589 people have browsed it

一:各个数据中的连接符

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<=7order by birthday desc

三:

select now() + interval &#39;1 days&#39;;
Copy after login
select now() + interval &#39;1 month&#39;;
Copy after login
select now() + interval &#39;1 years&#39;;
Copy after login
四:
Copy after login
SqlServer中进行日期计算时,用到函数
Copy after login
CONVERT(),DATEPART(),getDate()
Copy after login
select CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+&#39;-&#39;+ CONVERT(varchar(2),DATEPART(month,birthday))+&#39;-&#39;+CONVERT(varchar(2),DATEPART(day,birthday)),120),datediff(day,CONVERT(varchar(10),getdate(),120),CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+&#39;-&#39;+ CONVERT(varchar(2),DATEPART(month,birthday))+&#39;-&#39;+CONVERT(varchar(2),DATEPART(day,birthday)),120))
Copy after login
from tablename where delflag=0 and status=0
Copy after login
and datediff(day,CONVERT(varchar(10),getdate(),120),CONVERT(varchar(10),CONVERT(varchar(4),DATEPART(year,getDate()))+&#39;-&#39;+ CONVERT(varchar(2),DATEPART(month,birthday))+&#39;-&#39;+CONVERT(varchar(2),DATEPART(day,birthday)),120))<=7
Copy after login
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

 更多相关教程请访问 MySQL视频教程

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template