[Python] How to get yesterday's date
tata-titi
Posted messages
43
Status
Membre
-
sebsauvage Posted messages 33284 Registration date Status Modérateur Last intervention -
sebsauvage Posted messages 33284 Registration date Status Modérateur Last intervention -
Is there an existing function or "conversion" that would allow for getting yesterday's date with ...time...???
Thank you
Thank you
Configuration: Windows XP Firefox 1.5.0.9
4 réponses
Hello
You are -1 on today's date :)
--
Without politeness, we would only meet to fight.
So one must either live alone or be polite.
You are -1 on today's date :)
--
Without politeness, we would only meet to fight.
So one must either live alone or be polite.
Alphonse Karr
It's not that simple if you want a date in the format "20070702"!
--------------------------------------------------------------------------------
today = time()
# 86400 = 24 h x 3600 seconds => 1 day in seconds!
yesterday = today - 86400
formatted = gmtime(yesterday)
if len(str(formatted[1]))<2:
first = "0" + str(formatted[1])
else:
first = str(formatted[1])
if len(str(formatted[2]))<2:
second = "0" + str(formatted[2])
else:
second = str(formatted[2])
concat = str(formatted[0]) + first + second
=== > because otherwise it could result in "200772"!!!
--------------------------------------------------------------------------------
today = time()
# 86400 = 24 h x 3600 seconds => 1 day in seconds!
yesterday = today - 86400
formatted = gmtime(yesterday)
if len(str(formatted[1]))<2:
first = "0" + str(formatted[1])
else:
first = str(formatted[1])
if len(str(formatted[2]))<2:
second = "0" + str(formatted[2])
else:
second = str(formatted[2])
concat = str(formatted[0]) + first + second
=== > because otherwise it could result in "200772"!!!
Merci pour les conseils
Eclipsse
so how do you indicate the date from one month ago?