How can I convert a DateField() value to unit timestamp representation in Django?
1 Answer
As the DateField() returns a native Python datetime.date instance, https://docs.python.org/2/library/datetime.html, it will be the same as converting a datetime.date object to a unix timestamp integer.. such as:
import time
import django.models as models
date = models.DateField()
unix_timestamp = int(time.mktime(date.timetuple()))
DateField()returnsdatetimeregular python object, there are many solutions on the web describing how to convert pythondatetimeobject to unix timestamp.