0

How can I convert a DateField() value to unit timestamp representation in Django?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • possible duplicate of [django Datefield to Unix timestamp](http://stackoverflow.com/questions/1259219/django-datefield-to-unix-timestamp) – Adam Link Jun 02 '15 at 18:25
  • `DateField()` returns `datetime` regular python object, there are many solutions on the web describing how to convert python `datetime` object to unix timestamp. – dydek Jun 02 '15 at 18:54

1 Answers1

1

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()))
Niklas9
  • 8,816
  • 8
  • 37
  • 60