Imran Imran - 10 months ago 56
Linux Question

start and end time of yesterday in time-stamp python

I want to get start time and end time of yesterday linux timestamp

import time
startDay = time.strftime('%Y-%m-%d 00:00:00')
print startDay
endDay =time.strftime('%Y-%m-%d 23:59:59')
print endDay

Output is:

2016-11-18 00:00:00

2016-11-18 23:59:59

this showing in string today start-time and end-time
I want to get yesterday start-time and end-time in linux time-stamp



Answer Source
import time
def datetime_timestamp(dt):
    time.strptime(dt, '%Y-%m-%d %H:%M:%S')
    s = time.mktime(time.strptime(dt, '%Y-%m-%d %H:%M:%S'))
    return int(s)