Put this in a model

def prettydate(d):
    try:
        dt = request.now - d
    except:
        return ''
    if dt.days>=365*2:
        return '%s years ago' % int(dt.days/365)
    elif dt.days>=365:
        return '1 years ago'
    elif dt.days>=60:
        return '%s months ago' % int(dt.days/30)
    elif dt.days>21:
        return '1 months ago'
    elif dt.days>=14:
        return '%s weeks ago' % int(dt.days/7)
    elif dt.days>=7:
        return '1 week ago'
    elif dt.days>=2:
        return '%s days ago' % int(dt.days)
    elif dt.days==1:
        return '1 day ago'
    else:
        return 'today'


On Feb 14, 3:13 pm, selecta <[email protected]> wrote:
> This is not 100% web2py related but I am sure if this will be answered
> many of you will profit at some point from it.
>
> Is there a python module that helps you to display dates and times
> nice e.g.
>
> just now (for within the last 5 minutes)
> 2 hours ago
> 2 days ago
> 15th February 2009
> ...
>
> I guess somebody must have done that already, right?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to