Re: Calculating relative time/distance from CURRENT_TIMESTAMP - Mailing list pgsql-sql

From Samuel Gendler
Subject Re: Calculating relative time/distance from CURRENT_TIMESTAMP
Date
Msg-id CAEV0TzBu+vDhYp9R8Eeu1iCH2++VwABQcK+wVdSEExLgszZv5Q@mail.gmail.com
Whole thread Raw
In response to Re: Calculating relative time/distance from CURRENT_TIMESTAMP  ("Gnanakumar" <gnanam@zoniac.com>)
Responses Re: Calculating relative time/distance from CURRENT_TIMESTAMP  ("Gnanakumar" <gnanam@zoniac.com>)
List pgsql-sql


On Thu, Aug 4, 2011 at 4:42 AM, Gnanakumar <gnanam@zoniac.com> wrote:

Hi Amitabh,

 

Yes, I already took a glance of the Date/Time functions.  But what I’m expecting is something more meaningful/user-friendly value to be returned than from the actual return value of these functions available here.  I’m just finding out whether this could be solved at query level itself.

 

For example, there is age(timestamp, timestamp) function.  If I call like this select age(current_timestamp, (current_timestamp - interval '1 day')) it returns

“1 day”.  But what I’m expecting to be returned from the function is something more meaningful/user-friendly to the end users.  In this case, I wanted it to return “yesterday”, similarly today, 15 minutes ago, 1 week ago, etc.


If you really want a flexible function for doing this, I suspect you could replicate the functionality of jquery's 'timeago' module in a stored proc relatively easily. http://timeago.yarp.com/ It is MIT licensed, so you can copy the logic without restriction.  It makes reference to being derivative of a ruby project, so you could probably grab that code and convert it to ruby-pg very easily.
 

pgsql-sql by date:

Previous
From: Charlie
Date:
Subject: Re: Calculating relative time/distance from CURRENT_TIMESTAMP
Next
From: "Gnanakumar"
Date:
Subject: Re: Calculating relative time/distance from CURRENT_TIMESTAMP