ca9163d9
ca9163d9

Reputation: 29159

Convert int back to datetime?

The database table with a datetime column is read and returned by a restful api.

from sqlalchemy import Column, DATETIME
class Table(base)
    datetime = Column(DATETIME)

However, the API return integers for the column datetime.

1622332800000
1622937600000
1623542400000
1624147200000

How to convert these values back to datetime?

Upvotes: 1

Views: 68

Answers (1)

Ahmed Ablak
Ahmed Ablak

Reputation: 738

You may try the following:

import datetime
timestamp = datetime.datetime.fromtimestamp(1002332800)
timestamp.strftime('%Y-%m-%d %H:%M:%S')

The output should be:

>>>> 2001-10-06 04:46:40

Upvotes: 1

Related Questions