APIs & Integrations

SSakhuja
Member

Converting CreateDate from long int format to actual date format in Python

Hello Everyone,

 

Need some help in converting longint date from Hubspot to actual date format in python. 

 

I am currently using API calls to fetch all values, currently, the date format I am getting from API results looks like -

 

'notes_last_updated': {'value': '1651032900000'},

 

Any help will be appreciated.

 

Thanks.

0 Upvotes
2 Replies 2
skimura
Contributor | Platinum Partner
Contributor | Platinum Partner

Converting CreateDate from long int format to actual date format in Python

@SSakhuja 

Hi.

 

How about this? (not tested)

 

 

from datetime import datetime

# msec to sec
timestamp = 1651032900000 / 1000

datetime_object = datetime.fromtimestamp(timestamp)

print("datetime_object = ", datetime_object)
# datetime_object = 2022-04-27 04:15:00
# If you need, format.

 

 

0 Upvotes
SSakhuja
Member

Converting CreateDate from long int format to actual date format in Python

Thanks for replying.

 

This works with one datetime like object, however if I use like pd.to_datetime(df['notes_last_updated'], unit='s') it converts to a proper datetime object for a dataframe (assuming the bigint is seconds).

 

But thanks for the reply, really helped with the idea if how to approch with this one.