I have a list of dates and hours. For each date, I would like to extract only the seconds value.
Here is my script :
import datetime format_string = "%Y-%m-%d %H:%M" now = datetime.datetime.now() date = ['2021-01-29 15:15', '2021-01-29 15:50', '2021-01-29 17:00'] date = [(datetime.datetime.strptime(i, format_string)-now) for i in date] print(date) And here is the output :
[datetime.timedelta(seconds=7269, microseconds=211221), datetime.timedelta(seconds=9369, microseconds=211221), datetime.timedelta(seconds=13569, microseconds=211221)] I just want the seconds for the three elements of the list 'data'