我有以下代碼:Python的日期匹配與MySQL
fixtures = StraightredFixture.objects.filter(soccerseason=soccerseason,fixturematchday=fixturematchday).order_by('fixturedate')
firstGameTime = str(fixtures[0].fixturedate).split()
currentTime = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")).split()
if firstGameTime >= currentTime:
selectteams = True
else:
selectteams = False
無論firstGameTime的日期是它總是返回False。兩個例子如下:
firstGameTime = ['2010-10-28', '11:30:00+00:00']
currentTime = ['2016-10-29', '10:51:50']
selectteams = False
firstGameTime = ['2010-10-30', '11:30:00+00:00']
currentTime = ['2016-10-29', '10:53:16']
selectteams = False
在第二個例子中,我希望它說真正的firstGameTime是30號,而currentTime的是第29屆。
我有一種感覺,它是與+00:00部分做的,但在如何解決這個問題上有所損失。任何幫助將不勝感激,非常感謝,艾倫。
你爲什麼將這些以字符串列表進行比較,而不是讓他們爲日期時間? –
在某處作爲解決方案在線閱讀它。我不需要,所以任何解決方案表示讚賞。 –