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';
Written by Denis Savitskiy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#