PostgreSQL date calculation function usage
PostgreSQL date calculation function usage
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'; 4: the functions CONVERT (), DATEPART (), and getDate () are used for date calculation in SqlServer ()
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
------------------------------------ Lili split line ------------------------------------
Install PostgreSQL 6.3 on yum in CentOS 9.3
PostgreSQL cache details
Compiling PostgreSQL on Windows
Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu
Install and configure phppgAdmin on Ubuntu
Install PostgreSQL9.3 on CentOS
Configure a Streaming Replication cluster in PostgreSQL
How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4
------------------------------------ Lili split line ------------------------------------
PostgreSQL details: click here
PostgreSQL: click here
This article permanently updates the link address: