6

my model

create = models.DateTimeField(auto_now_add=True)

how to get unix time from this field?

datetime.datetime.timestamp()

but I need int

1 Answer 1

9

Here create is a simple python datetime.datetime instance itself.

For python less than 2.x

You can do .

my_model = MyModel()
int(my_model.create.strftime('%s'))

For python 3.3+

You can just do

my_model = MyModel()
my_model.create.timestamp()
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.