Login

datemate

Author:
catellar
Posted:
August 24, 2011
Language:
Python
Version:
1.3
Score:
0 (after 2 ratings)

This wil format the date to today at 1:03 pm , yesterday at 9:13 pm, 22 August at 10:08 pm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def datemate(value):
	hoy = datetime.date.today()
	if value.year == hoy.year:
		fecha = format(value, "d F").replace(' 0', ' ')
	else:
		fecha = format(value, "d F Y").replace(' 0', ' ')
	ayer = hoy - datetime.timedelta(1)
	hora = format(value, "g:i A").lower()
	if value.year == hoy.year and value.month == hoy.month and value.day == hoy.day:
		fecha = "today"
	if value.year == ayer.year and value.month == ayer.month and value.day == ayer.day:
		fecha = "yesterday"
	return fecha + " " + "at" + " " + hora

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.