PostgreSQL date calculation function usage

Source: Internet
Author: User

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:

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.