Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql datediff

- Difference between Dec 29, 2011 23:00 and Dec 31, 2011 01:00 in days
  SELECT DATE_PART('day', '2011-12-31 01:00:00'::timestamp - '2011-12-29 23:00:00'::timestamp);
  -- Result: 1
Comment

DATEDIFF minute postgres

  -- Difference between Dec 30, 2011 08:54:55 and  Dec 30, 2011 08:56:10 in minutes
  SELECT (DATE_PART('day', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp) * 24 * 60 + 
               DATE_PART('hour', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp)) * 60 +
               DATE_PART('minute', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp);
  -- Result: 1
 
  -- Time only
  SELECT DATE_PART('hour', '08:56:10'::time - '08:54:55'::time) * 60 +
              DATE_PART('minute', '08:56:10'::time - '08:54:55'::time);
  -- Result: 1
Comment

postgresql datediff

-- Difference between Oct 02, 2011 and Jan 01, 2012 in years
  SELECT DATE_PART('year', '2012-01-01'::date) - DATE_PART('year', '2011-10-02'::date);
  -- Result: 1
Comment

postgresql datediff

-- Difference between Oct 02, 2011 and Jan 01, 2012 in years
  SELECT DATE_PART('year', '2012-01-01'::date) - DATE_PART('year', '2011-10-02'::date);
  -- Result: 1
Comment

PREVIOUS NEXT
Code Example
Sql :: Select without null values sql 
Sql :: how to find the number of rows updated in oracle pl/sql 
Sql :: sql groub by count 
Sql :: how to create a table in sql 
Sql :: how to connect postgresql database with java 
Sql :: declarative base sqlalchemy 
Sql :: mysql kill 
Sql :: creating postgresSQL database using the the shell 
Sql :: update one column from another column in same table 
Sql :: return result of function in postgresql 
Sql :: how to lock table in mysql 
Sql :: Postgres - Login and connect as default user 
Sql :: sqlite create tables 
Sql :: spring boot working with sql database connection 
Sql :: sql between 
Sql :: how to count number of rows in sql 
Sql :: copy data from one table to another mysql 
Sql :: what is the difference between clustered and non-clustered index in sql server 
Sql :: regenerate assets odoo 
Sql :: mysql select distinct date from timestamp 
Sql :: postgres 11 add primary key 
Sql :: mysql select count 
Sql :: user_dependencies 
Sql :: how to find all children of a record with only parent ID in sql 
Sql :: sum value by month sql 
Sql :: sql display max value 
Sql :: creating table in mysql 
Sql :: rollback in sql 
Sql :: select true if exists on another table or false sqlserver 
Sql :: oracle parameter 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =