Harry
Harry

Reputation: 31

subtract one day from timestamp - python

'I'm trying to subtract a day from this date 1590074712 in order to make 1590008151 but can't figure out any way to achieve that.

I've tried with:

from datetime import datetime

ts= 1590074712 
date = datetime.timestamp(ts) - timedelta(days = 1)
print(date)

How can I subtract a day from a date in the above format?

I want the output in timestamp

Upvotes: 0

Views: 725

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195408

Use datetime.fromtimestamp():

from datetime import datetime, timedelta

ts= 1590074712
date = datetime.fromtimestamp(ts) - timedelta(days = 1)
print(date)

Prints:

2020-05-20 15:25:12

Upvotes: 5

Related Questions