PostgreSQL date calculation functions, postgresql Functions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.