0

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

2
  • possible duplicate of django Datefield to Unix timestamp Commented Jun 2, 2015 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. Commented Jun 2, 2015 at 18:54

1 Answer 1

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()))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.