Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find previous calendar day in python [duplicate]

Possible Duplicate:
How can I subtract a day from a python date?

I have a set of files that I'm saving by date, year_month_day.txt format. I need to open the previous day's text file for some processing. How do I find the previous day's date in python?

like image 803
Xavier Avatar asked Jun 20 '10 23:06

Xavier


People also ask

How can I get previous date from datetime?

You just have to subtract no. of days using 'timedelta' that you want to get back in order to get the date from the past. For example, on subtracting two we will get the date of the day before yesterday.

How do I get the first and last day of the current month in Python?

There are a few ways to do this, but I've gone with the following: last_date = datetime(year, month + 1, 1) + timedelta(days=-1) . This will calculate the first date of the following month, then subtract 1 day from it to get the last date of the current month.


1 Answers

Here you go:

>>> print datetime.date.today()-datetime.timedelta(1)
>>> 2010-06-19
like image 186
Wai Yip Tung Avatar answered Sep 20 '22 23:09

Wai Yip Tung