Re: Calculating relative time/distance from CURRENT_TIMESTAMP

From: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
To: gnanam(at)zoniac(dot)com
Cc: Amitabh Kant <amitabhkant(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Calculating relative time/distance from CURRENT_TIMESTAMP
Date: 2011-08-04 22:24:45
Message-ID: CAEV0TzBu+vDhYp9R8Eeu1iCH2++VwABQcK+wVdSEExLgszZv5Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Aug 4, 2011 at 4:42 AM, Gnanakumar <gnanam(at)zoniac(dot)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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gnanakumar 2011-08-05 09:07:08 Re: Calculating relative time/distance from CURRENT_TIMESTAMP
Previous Message Charlie 2011-08-04 21:54:05 Re: Calculating relative time/distance from CURRENT_TIMESTAMP