Can you coerce the data type to a string to perform this calculation?
date_time_obj = datetime.strptime(str(date), '%Y-%m-%d %H:%M:%S')
Answer from Paul Wildenhain on Stack Overflow Top answer 1 of 5
23
Can you coerce the data type to a string to perform this calculation?
date_time_obj = datetime.strptime(str(date), '%Y-%m-%d %H:%M:%S')
2 of 5
10
If it says "strptime() argument 1 must be str, not Timestamp", likely that you already have the pandas.Timestamp object, i.e., it is not a string but a parsed date time, only it is in Pandas' format, not Python's. So to convert, use this:
date_time_obj = date.to_pydatetime()
instead of date_time_obj = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
Top answer 1 of 16
451
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1322697600.0
2 of 16
84
I use ciso8601, which is 62x faster than datetime's strptime.
t = "01/12/2011"
ts = ciso8601.parse_datetime(t)
# to get time in seconds:
time.mktime(ts.timetuple())
You can learn more here.
Videos
Convert string date to timestamp in Python
02:30
Convert string date to timestamp in Python - YouTube
01:24
How to convert a string date to the timestamp in Python - YouTube
00:26
Convert Unix timestamp string to readable format in Python ๐ ...
00:23
Convert string date to timestamp in Python #shorts - YouTube
03:50
Convert string to timestamp python - YouTube
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.Timestamp.strftime.html
pandas.Timestamp.strftime โ pandas documentation
Return a formatted string of the Timestamp. This method converts a Timestamp to a string according to the given format string, using the same directives as the standard libraryโs datetime.datetime.strftime().
TutorialsPoint
tutorialspoint.com โบ how-to-convert-timestamp-string-to-datetime-object-in-python
How to convert timestamp string to datetime object in Python?
May 15, 2025 - It accepts a format string that you can use to get the result you want. The following are the directives that it supports. The following program converts the timestamp to a datetime object using datetime.fromtimestamp() function and format it using strftime() function -
Timestamp Converter
timestamp.online
Timestamp To Date Converter
Convert timestamp to date or date to timestamp easily. Learn how to convert timestamp to date in Python, PHP, JavaScript, Bash, ...
DigitalOcean
digitalocean.com โบ community โบ tutorials โบ python-string-to-datetime-strptime
How To Convert a String to a datetime Object in Python | DigitalOcean
December 13, 2024 - In this article, youโll use strptime() to convert strings into datetime and struct_time() objects. Deploy your Python applications from GitHub using DigitalOcean App Platform.
DataCamp
datacamp.com โบ tutorial โบ converting-strings-datetime-objects
Convert String to DateTime in Python: Complete Guide with Examples | DataCamp
June 8, 2018 - Learn how to convert strings to datetime objects in Python using strptime(), dateutil, and pandas. Includes code examples, timezone handling, and troubleshooting tips.
Programiz
programiz.com โบ python-programming โบ datetime โบ strftime
Python strftime() - datetime to string
from datetime import datetime timestamp ... date and time representation. We also recommend you to check Python strptime(). The strptime() method creates a datetime object from a string....
DZone
dzone.com โบ coding โบ javascript โบ python: converting a date string to timestamp
Python: Converting a Date String to Timestamp
October 29, 2014 - So the first step is to translate that into a Python date โ the strftime section of the documentation is useful for figuring out which format code is needed: import datetime date_text = "13SEP2014" date = datetime.datetime.strptime(date_text, "%d%b%Y") print(date) ... The next step was to translate that to a UNIX timestamp. I thought there might be a method or property on the Date object that I could access but I couldnโt find one and so ended up using calendar to do the transformation:
Python.org
discuss.python.org โบ python help
Timestamp convertion - Python Help - Discussions on Python.org
October 11, 2021 - My friend passed to me a log pulled from a device with timestamp shown below. How to plot this in python? Do I need to convert the values of timestamp first or python can handle it? How to interpret this kind of timestamp format? Noise Timestamp 234 1624284672 5.8 1624284672 478 1624284674
Saturn Cloud
saturncloud.io โบ blog โบ how-to-convert-timestamp-to-string-value-in-python-pandas-dataframe
How to Convert Timestamp to String Value in Python Pandas Dataframe | Saturn Cloud Blog
December 27, 2023 - One common task is converting timestamps to string values in a Pandas dataframe. In this article, we will explore how to do this efficiently and effectively. ... A timestamp is a sequence of characters or encoded information that represents the date and time at which a particular event occurred. In Python, timestamps are represented as datetime objects.
GeeksforGeeks
geeksforgeeks.org โบ python โบ how-to-convert-timestamp-string-to-datetime-object-in-python
How to convert timestamp string to datetime object in Python? - GeeksforGeeks
August 23, 2025 - If the timestamp string is in ISO 8601 format (i.e., "YYYY-MM-DD HH:MM:SS"), fromisoformat() is the cleanest and most efficient method to convert it to a datetime object.
PYnative
pynative.com โบ home โบ python โบ python datetime โบ timestamp in python
Python Timestamp With Examples โ PYnative
December 5, 2021 - from datetime import datetime # timestamp ts = 1617295943.17321 # convert to datetime dt = datetime.fromtimestamp(ts) print("The date and time is:", dt) # output 2021-04-01 22:22:23.173210Code language: Python (python) Run ยท We can convert the timestamp string using the datetime formatting.
w3resource
w3resource.com โบ python-exercises โบ date-time-exercise โบ python-date-time-exercise-6.php
Python: Convert unix timestamp string to readable date - w3resource
July 22, 2025 - After converting the timestamp into a datetime object, it formats the datetime object into a string representation using the "strftime()" method with the specified format '%Y-%m-%d %H:%M:%S'. This format represents the datetime as "Year-Month-Day Hour:Minute:Second". Finally, it prints the formatted datetime string. ... Write a Python program to convert a Unix timestamp string to a formatted date string in "DD-MM-YYYY HH:MM:SS" format.