get "yesterday's" date in iso format

G

Guest

Hi,

I am trying to find a simple way to get "yesterday's" date. I know I can
build various check to seee if we are in leap year, if we are the 1st then
yesterday is the 31(or 30 depending of the month) etc. but there is got to
be a simpler way than that. I was thinking of using the gmtime (field 7 as
you can see int the code)then substract one, then use strptime to rebuild
the time but it doesn't work(probably because I misunderstood strptime):

improt time
gmt = time.gmtime()
yesterdaytime = str(int(gmt[7]) - 1)
print gmt[7]
print yesterdaytime
newtime = time.strptime(yesterdaytime,'%j')
print newtime
(1900, 1, 22, 0, 0, 0, 0, 22, -1)

can someone enlighten me please?

Thanks
David
 
T

Tim Heaney

I am trying to find a simple way to get "yesterday's" date. I know I can
build various check to seee if we are in leap year, if we are the 1st then
yesterday is the 31(or 30 depending of the month) etc. but there is got to
be a simpler way than that.

Since time.time() gives the time in seconds since the epoch, you could
just subtract a day from that to get yesterday.
(2004, 1, 22, 4, 36, 3, 3, 22, 0)

I hope this helps,

Tim
 
G

Gerrit Holl

Tim said:
Since time.time() gives the time in seconds since the epoch, you could
just subtract a day from that to get yesterday.

Even better:
22

yours,
Gerrit.

--
179. If a "sister of a god," or a prostitute, receive a gift from her
father, and a deed in which it has been explicitly stated that she may
dispose of it as she pleases, and give her complete disposition thereof:
if then her father die, then she may leave her property to whomsoever she
pleases. Her brothers can raise no claim thereto.
-- 1780 BC, Hammurabi, Code of Law
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top