| Reply | « Previous Thread | Next Thread » |
|
Hello, I want to get yesterday's date(YYYY-MM-DD):
I tried to use import datetime today = datetime.date.today( ) yesterday = today - datetime.timedelta(days=1) tomorrow = today + datetime.timedelta(days=1) print yesterday, today, tomorrow but it wasn't working, what's wrong? thx |
| mozillaman |
| View Public Profile |
| Find all posts by mozillaman |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
You should use time module, it would be easier ![]() Just get today's date and subtract 1: Code:
import time today = time.localtime()[2] yesterday = today-1 print yesterday This should work, and it's much easier, isn't it? ![]() Hope it helps, Rafael. |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Online
Forum Nokia Champion
|
|
|
Quote:
So instead use something like this: Code:
import time yesterday=time.localtime(time.time()-86400)[2] print yesterday |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
Yes, it could be your formula too, but with mine it's also fine ![]() Just use some if for detecting if it's the first day of the month ![]() Thanks for completing with your formula! BR, Rafael. |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Online
Forum Nokia Champion
|
|
Yes, that if is important. Without it it might not make sense.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Re: Urgent Help with Comparing Time & Dates please | scc | General Symbian C++ | 7 | 2008-12-30 16:28 |
| Problems with negative dates (before 01/01/1970) | squalbee | Python | 8 | 2008-08-08 22:40 |
| Calculating dates using Calendar | cs04rrj | Mobile Java General | 2 | 2008-01-17 22:15 |
| Nokia 6235 BUGS: images, extras and dates | bioninja | General Discussion | 0 | 2006-12-21 04:22 |
| 6310i Wallet Expiry Dates | dmarson | General Discussion | 2 | 2004-01-22 16:50 |