0

I'm looking to insert the current system timestamp into a field on a database. I don't want to use the server side now() function and need to use the python client's system timestamp. What MySQL datatype can store this value, and how should I insert it? Is time.time() sufficient?

3
  • i think it's a different question. 'm looking for a unix timestamp (more accuracy), not a daily datetime as shown in the examples you cited. also, still not sure what datatype to use on the db side to store this. Commented Jun 23, 2014 at 13:36
  • 2
    is there a reason not to use the DATETIME data type? dev.mysql.com/doc/refman/5.1/en/datetime.html Commented Jun 23, 2014 at 14:16
  • "Is time.time() sufficient?" That's up to you to decide. So? Is it sufficient for your use case? If so, it's just a float value... store it as one. Commented Jun 23, 2014 at 17:39

2 Answers 2

1

time.time() is a float, if a resolution of one second is enough you can just truncate it and store it as an INTEGER.

Sign up to request clarification or add additional context in comments.

Comments

1
>>> import datetime
>>> datetime.datetime.now().strftime("%s")
'1403545051'

2 Comments

Not working in python 3.6
>>>int(datetime.datetime.now().timestamp())

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.