一:各个数据中的连接符
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 '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
更多相关教程请访问 mysql视频教程