473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10479
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************ **********@v46g 2000cwv.googleg roups.com>,
"Thierry Lam" <la********@gma il.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
11835
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 date. thanks gavin
3
1334
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 the last inserted record. It's easy to do Select * from table where field1=x ORDER BY dtModificationTime. That works, but it hits all the records that match the field. I need to come back with an exact hit. Can someone point me in the...
3
1953
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 a date sometime in the future when I should contact the client again. The problem I now have is that I am so ignorant of the actual program that I do not know how to construct a simple query or report (you see I don't even know what I want is...
15
1946
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, when viewing the page using the display: <?= date('n/j/Y', strtotime($result->record_entered)) ?>
2
1540
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 settings and then act accordingly to these date settings. eg: By default, today's date is entered into txtDate. Then, the packing list number is automatically generated as yyyymmssss where ssss is the serial sequential number. I have written code...
3
2336
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 " & _ BeginDate & " AND " & EndDate I want to display records that are from three days ago to the present.
3
1126
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 example below I only want to see ABC Day Care 11/5/07. FACILITY ABC Day Care INVESTIGATIONS 1/1/06 4/18/07 11/5/07
5
5794
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 suggest a tidy looking way of doing this. Not tested below version but there is a cleaner way surelySELECT * FROM invoices WHERE date>=(CAST( FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME ) -1) AND date<=(CAST( FLOOR( CAST( GETDATE() AS FLOAT...
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.