Last Updated: February 25, 2016
·
799
· sadfuzzy

Time functions in PostgreSQL

After ruby Time.now, 1.day, 2.weeks, 3.years, etc. methods, we need this feature in PostgreSQL like 'now()', 'today()'.

You can use these functions:

select TIME 'allballs';
select now();
select '2 weeks 3 days 4 hours 15 minutes'::interval;
select (now() - '2 weeks 3 days 4 hours 15 minutes'::interval)::date;

select DATE 'yesterday';
select DATE 'today';
select DATE 'now';
select DATE 'tomorrow';

select TIMESTAMP 'yesterday';
select TIMESTAMP 'today';
select TIMESTAMP 'now';
select TIMESTAMP 'tomorrow';