I have my date and time field in the form Timestamp('2016-12-02 22:25:44'). I want this to be converted to integer millisecond form in python. Any suggestion how to do this?
Asked
Active
Viewed 800 times
0
-
What's `Timestamp`? – chepner Jul 19 '18 at 14:22
-
1What do you mean by "integer millisecond form"? Can you give an example of the output? – Joel Jul 19 '18 at 14:23
-
1Like milliseconds since 1970 or some epoch? – doctorlove Jul 19 '18 at 14:23
-
Is that your value a string `Timestamp('2016-12-02 22:25:44')` or a timestamp object with datetime '2016-12-02 22:25:44'? – SnowBG Jul 19 '18 at 14:24
-
Welcome to stackoverflow. Please edit your question to include a clear problem description and if possible some minimal code. For guidance please check the [how to ask](https://stackoverflow.com/help/how-to-ask) page and [how to create a minimal example](https://stackoverflow.com/help/mcve). – 5th Jul 19 '18 at 14:29
1 Answers
0
Python is quite good at this. The following function worked for me in many cases.
from dateutil.parser import parse
parse('2016-12-02 22:25:44').strftime("%s")
(just read the comments, thought you meant a string, not sure if this answer applies to what you ask but seems not clear yet)

vladmihaisima
- 2,119
- 16
- 20
-
Thank you for the answer, but I am getting the error "Invalid format string" if I use parse('2016-12-02 22:25:44').strftime("%s"). – Bineeta Saikia Jul 20 '18 at 06:31
-
The above code works for me for python 2.7.5 and python 3.4.8. Not sure what else can go wrong. – vladmihaisima Jul 20 '18 at 08:07