Human format Date representation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
@register.filter(name='date_human')
def humanize_date(time):
    if not time:
        return

    format = "%b %d"
    current = datetime.datetime.now().day
    object_date =  time.day

    if current - object_date == 0:
        return "today"

    if current - object_date == 1:
        return "yesterday"

    else:
        if not current.year == time.year:
            format = 'n/j/y'
        date_str = time.strftime(format)
        return "%s" % date_str

More like this

  1. Increment a variable in a Template by sachingupta006 1 year, 2 months ago
  2. Smart i18n date diff (twitter like) by Batiste 4 years, 1 month ago
  3. parse date template tag by robhudson 3 years, 7 months ago
  4. Widget for DateTime values on Geraldo Reports by marinho 4 years, 1 month ago
  5. Display arbitrary models by bjornkri 4 years, 10 months ago

Comments

(Forgotten your password?)