Why I'm getting the date of yesterday

Discussion in 'Python' started by Hussein B, Jan 20, 2009.

  1. Hussein B

    Hussein B Guest

    Hey,
    I'm trying to get the get the date before today, I tried this:
    d = datetime.now() - timedelta(days = -1)
    But I got the date of tomorrow.
    when I tried:
    d = datetime.now() + timedelta(days = -1)
    I got the date of yesterday.
    Would you please explain to me why I got the date of yesterday when I
    added the both objects?
    Thanks.
    Hussein B, Jan 20, 2009
    #1
    1. Advertising

  2. 2009/1/20 Hussein B <>:
    > Hey,
    > I'm trying to get the get the date before today, I tried this:
    > d = datetime.now() - timedelta(days = -1)
    > But I got the date of tomorrow.


    That's because you are taking away a negative value. This is like doing:

    >>> 0 - (-1)

    1

    --
    Cheers,
    Simon B.
    Simon Brunning, Jan 20, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -vr_stupids

    get "yesterday's" date in iso format

    -vr_stupids, Jan 23, 2004, in forum: Python
    Replies:
    4
    Views:
    4,156
    -vr_stupids
    Jan 24, 2004
  2. Thierry Lam

    Finding yesterday's date with datetime

    Thierry Lam, May 15, 2006, in forum: Python
    Replies:
    2
    Views:
    489
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,661
    Smokey Grindel
    Dec 2, 2006
  4. Tim Golden
    Replies:
    0
    Views:
    526
    Tim Golden
    Oct 22, 2009
  5. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    418
    D'Arcy J.M. Cain
    Oct 22, 2009
Loading...

Share This Page