Answer the question
In order to leave comments, you need to log in
Convert milliseconds to date of specific format?
Please help me convert milliseconds to a datetime date for a query in SalesForce
Input string or number = 1640256042000
Output format = 2011-04-26T10:00:00-08:00
In the request it will look like this - "SELECT Name FROM Account WHERE CreatedDate > 2011-04-26T10:00:00-08:00" - so I checked, it returns the data, this is a request to the SF database
Answer the question
In order to leave comments, you need to log in
from datetime import datetime, timezone
timestamp = 1640256042000
dt = datetime.fromtimestamp(timestamp/1000)
print(dt)
>>> 2021-12-23 12:40:42
dt = datetime.fromtimestamp(timestamp/1000, tz=timezone.utc).isoformat()
print(dt)
>>> 2021-12-23T10:40:42+00:00
The string 1640256042000 doesn't look like milliseconds; maybe it's just a Unix timestamp? The format is also not clear to me, but it looks more like the ISO format.
If so then:
from datetime import datetime
parsed_time = datetime.fromtimestamp(input_time)
query_format_time = parsed_time.isoformat()
query = "SELECT Name FROM Account WHERE CreatedDate > '%s'" % query_format_time
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question