473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Finding yesterday's date with datetime

Is there an easy way to determine the yesterday's date(year-month-day)
from the python datetime library if I know today's date?

Thanks
Thierry

May 15 '06 #1
2 10468
Try something like this...

HTH. A.
from datetime import *

d1 = datetime( year=2006, month=5, day=15)
d2 = datetime.now()

for d in [d1,d2]:
yest = d - timedelta(days =1 )

print "%s -> %s" % (d, yest)

May 15 '06 #2
In article <11**********************@v46g2000cwv.googlegroups .com>,
"Thierry Lam" <la********@gmail.com> wrote:
Is there an easy way to determine the yesterday's date(year-month-day)
from the python datetime library if I know today's date?


from datetime import datetime, timedelta

today = datetime.today()
yesterday = today - timedelta(1)

# See the .month, .day, and .year fields of yesterday

Cheers,
-M

--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
May 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
3
by: JohnnyRuin | last post by:
Hi, My table has int Field1 and DateTime dtModificationTime. I maintain a history of changes to the table by inserting a new record with a new dtModificationTime. I need to be able to find...
3
by: Gary | last post by:
Sorry to waste everyone's time with a query which is so simple, but as a new user of Access I have created a client database and one of the fields is "next contact due" as the name implies, this is...
15
by: comp.lang.php | last post by:
$result->record_entered contains the current date as set up by MySQL (entered as "now()"). I verified that in the database the date is "now()", which in this case will be "2/9/2006". However,...
2
by: tricard | last post by:
Good morning, I am writing code to create a packing list number that is based on the date entered from the workstation that the user is on. However, I do not know how to determine the date...
3
by: Jim in Arizona | last post by:
I'm having difficulty figuring out how to find the date three days from today's date. I'm trying to use an sql select statement, like so: "SELECT * FROM TableA " & _ "WHERE DateColumn BETWEEN...
3
by: Luis Palacios | last post by:
I am trying to query the last/latest investigation for a facility using a date field. Each facility will have different types of investigations, I only want the last investigation performed. For the...
5
code green
by: code green | last post by:
I need to do a query something like SELECT * FROM invoices WHERE date= 'yesterdays date'It is not as simple as one might think which means ideas I have looked at vary widly. Could someone please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.