You Are Here:

Community: Developer Discussion Boards

#1 Old Dates - 2008-11-01, 16:16

Join Date: Oct 2008
Posts: 5
mozillaman
Offline
Registered User
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
Reply With Quote

#2 Old Re: Dates - 2008-11-01, 16:56

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by mozillaman View Post
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
Hi mozzilaman,

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.
Reply With Quote

#3 Old Re: Dates - 2008-11-02, 12:23

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Online
Forum Nokia Champion
Quote:
Originally Posted by Rafael T. View Post
Hi mozzilaman,

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.
Suppose today is the first day of the month. So accroding to your formula, yesterday would be the 0th day.

So instead use something like this:
Code:
import time

yesterday=time.localtime(time.time()-86400)[2]
print yesterday
Reply With Quote

#4 Old Re: Dates - 2008-11-02, 12:51

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by bogdan.galiceanu View Post
Suppose today is the first day of the month. So accroding to your formula, yesterday would be the 0th day.

So instead use something like this:
Code:
import time

yesterday=time.localtime(time.time()-86400)[2]
print yesterday
Hi bogdan,

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.
Reply With Quote

#5 Old Re: Dates - 2008-11-02, 13:17

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Online
Forum Nokia Champion
Quote:
Originally Posted by Rafael T. View Post
Hi bogdan,

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.
Yes, that if is important. Without it it might not make sense.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia