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 4 4514
On Thu, 22 Jan 2004, ne***********************@quanta1.wo...pidspambot.com wrote: I am trying to find a simple way to get "yesterday's" date. import datetime today = datetime.date.today() today
datetime.date(2004, 1, 23) yesterday = today - datetime.timedelta( 1 ) yesterday
datetime.date(2004, 1, 22)
--
\ "We must become the change we want to see." -- Mahatma Gandhi |
`\ |
_o__) |
Ben Finney <http://bignose.squidly.org/> ne***********************@quanta1.wo...pidspambot.com writes: 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. import time time.gmtime(time.time()-24*60*60)
(2004, 1, 22, 4, 36, 3, 3, 22, 0)
I hope this helps,
Tim
Tim Heaney wrote: ne***********************@quanta1.wo...pidspambot.com writes: I am trying to find a simple way to get "yesterday's" date.
Since time.time() gives the time in seconds since the epoch, you could just subtract a day from that to get yesterday.
Even better: from datetime import date, timedelta (date.today() - timedelta(1)).day
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
--
PrePEP: Builtin path type http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach: http://people.nl.linux.org/~gerrit/english/
On Fri, 23 Jan 2004 17:54:15 +0100, Gerrit Holl wrote: Tim Heaney wrote: ne***********************@quanta1.wo...pidspambot.com writes: > > I am trying to find a simple way to get "yesterday's" date.
Since time.time() gives the time in seconds since the epoch, you could just subtract a day from that to get yesterday.
Even better:
from datetime import date, timedelta (date.today() - timedelta(1)).day
22
Excellent. I guess I skipped the timedela section of the datetime module.
Thanks a lot,
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Don Vaillancourt |
last post by:
What's going on with Javascript.
At the beginning there was the "undefined" value which represented an
object which really didn't exist then came the null keyword. But
yesterday I stumbled...
|
by: Martien van Wanrooij |
last post by:
I would like to retrieve, let us say, the First Monday after a certain date,
so my (imaginary) function
could be something like
echo weekdayAfter("28 July 2005", "Monday") should return "1 August...
|
by: bg |
last post by:
Hi!
How do I check if "date" exists before using that code?
I've built a RSSreader and sometimes there's a date in it and sometimes not.
How can I check if it exists to avoid crash...
|
by: Emi Lu |
last post by:
Hello all,
I have a question about "date" & "timestamp" types in PostgreSQL. I want
to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for
them. However, it seems that PostgreSQL...
|
by: Florian G. Pflug |
last post by:
Hi
Since sometime yesterday, my postgresql (7.4.5) reports
"ERROR: cannot compare arrays of different element types",
when I analyze a specific table in my database.
Here is the tables...
|
by: Phil Powell |
last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm
// NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
AND THUS EXPIRE
function setCookie(name, value, days, docObj)...
|
by: 2Barter.net |
last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA
Inbox
Reply
Reply to all
Forward
Print
Add 2Barter.net to Contacts list
Delete this message
Report phishing
Show original
|
by: Just_a_fan |
last post by:
Some folks have searched, from time to time, for a dual axis MSChart
with different scales on the two Y axes. The sample, extracted from
running code I wrote, produces a graph with MSChart (VB9)...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |