The date calculation function for PostgreSQL uses

Source: Internet
Author: User
Tags postgresql

One: Connectors in individual data

Connector for SQL Server: + (plus)

SQLite's connector:. (dot)

Connector for PostgreSQL: | | Or

Two:

Today, when PostgreSQL calculates the date, I turn over some information, rarely, record it!

The functions and variables used in these

To_char (), Date (), now (), current_date

Calculates the difference of two dates

Current_date is today's date, as: 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

Three:

select  Now () +  interval  '  1 days  "   
select  Now () +  interval  '  1 month  "   
Select + ' 1 Years '
Four:
when you perform date calculations in SQL Server, use the function
CONVERT (), DATEPART (), GetDate ()
Select CONVERT (varchar), CONVERT (varchar (4), DATEPART (Year,getdate ())) + '-' + CONVERT (varchar (2), DATEPART (month, Birthday) + '-' +convert (varchar (2), DATEPART (Day,birthday)), DateDiff (day,convert (varchar), GETDATE (), 120) , convert (varchar), 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

Birthday desc

The date calculation function for PostgreSQL uses

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.