PostgreSQL date calculation functions, postgresql Functions
I. connector in each data
SqlServer connector: + (plus sign)
Sqlite connector:. (point)
PostgreSQL connector: | (OR)
II:
Today, when I was computing data in PostgreSQL, I had to record a few materials ~!
Functions and variables used
To_char (), Date (), now (), current_date
Calculate the difference between two dates
Current_date is the date of today, which is
Date ('1970-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
III:
select now() + interval '1 days';
select now() + interval '1 month';
select now() + interval '1 years';
IV:
SQL Server uses functions for date calculation.
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