Pretty dates

It is often useful to represent a datetime not as “2009-07-25 14:34:56” but as “one year ago”. web2py provides a utility function for this:

  1. import datetime
  2. d = datetime.datetime(2009, 7, 25, 14, 34, 56)
  3. from gluon.tools import prettydate
  4. pretty_d = prettydate(d, T)

The second argument (T) must be passed to allow internationalization for the output.