Getting a "Days Since" computed column in Postgres
When writing a query, especially for a dashboard, you might have a date column but want to show the distance between that date and now, instead of just the date. For example: Days Since Last Signin is more immediately useful than Last Signin Date.
To get that in Posgres, you can use the EXTRACT and AGE functions like so:
extract(days from age(current_timestamp, users.current_sign_in_at)) as days_since_signin,
Written by Jeremy Raines
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Postgres
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#