python中的数组日期数据不等于当前日期

时间:2019-03-10 07:58:30

标签: arrays python-3.x list append

在这里编码

from datetime import datetime

now = datetime.now()
date_now = now.strftime("%Y-%m-%d")
import datetime
history = [
       [1, 'Prosenjit Das', None, None],
       [2, 'Linda', datetime.date(2019, 3, 6), datetime.time(17, 50, 18)],
       [4, 'Sudipto Rahman', datetime.date(2019, 3, 6), datetime.time(20, 56, 36)],
       [5, 'Phan Tran', None, None, None, None, None, None, None, None, 'Phan Tran'],
       [6, 'Ely Tran', datetime.date(2019, 3, 7), datetime.time(15, 4, 32)],
       [7, 'Anna', datetime.date(2019, 3, 7), datetime.time(15, 34, 37)],
       [9, 'Arif', datetime.date(2019, 3, 7), datetime.time(19, 32, 50)],
       [3, 'Engineering', datetime.date(2019, 3, 8), datetime.time(10, 49, 58)],
       [10, 'Natalia', datetime.date(2019, 3, 9), datetime.time(13, 35, 20)],
       [11, 'Olga', datetime.date(2019, 3, 9), datetime.time(13, 37, 47)],
       [12, 'Elena', datetime.date(2019, 3, 9), datetime.time(13, 38, 3)],
       [13, 'Sofia', None, None],
       [14, 'Victoria', datetime.date(2019, 3, 9), datetime.time(13, 38, 35)],
       [19, 'Prosenjit Das', datetime.date(2019, 3, 10), datetime.time(11, 25, 43)],
       [18, 'Prosenjit Das', datetime.date(2019, 3, 10), datetime.time(11, 4, 25)],
       [8, 'Julia', datetime.date(2019, 3, 7), datetime.time(18, 59, 12)],
       [15, 'Marina', datetime.date(2019, 3, 9), datetime.time(13, 59, 39)],
       [16, 'Smith', datetime.date(2019, 3, 9), datetime.time(13, 59, 58)],
       [17, 'Nazrul Islam', None, None]
]
#print(history)
latest_history = []
for h in history:
    history_last_date = h[2]
    if history_last_date == date_now:
        latest_history.append(h[0])
    else:
        print(history_last_date,"!=",date_now)
print(latest_history,'\n')

My Output

在这张照片中,您可以看到id 18和19的格式都相同,但使用了date_now格式,但是这到底有什么问题。 根据我的条件18和19,id将被追加到我的last_history列表中,但这是空的。

谢谢。

0 个答案:

没有答案