Am I asking too much from datetime?

Discussion in 'Python' started by thehaas, Jun 1, 2004.

  1. thehaas

    thehaas Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    I'm trying to use the datetime module. The following seems to work
    any day except the first day of the month:
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    ValueError: day is out of range for month

    In other languages (specifically Java, but I'm sure these are others),
    this would come out as "2004-05-31".

    Is this is a bug, or outside of the functionality of datetime?


    - --
    Mike Hostetler

    http://www.binary.net/thehaas
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAvGe4aP33v4T41CURAkQGAKChO0yxPDxHwXHTsNOb0eO92zECGgCdHKZ2
    Irj6f33KpdXvwxsIhkM+Bo8=
    =IRWr
    -----END PGP SIGNATURE-----
     
    thehaas, Jun 1, 2004
    #1
    1. Advertisements

  2. thehaas

    Yermat Guest

    Of course it does not work !
    0 is not a valid day...
    You should do something like:
    2004-05-31
     
    Yermat, Jun 1, 2004
    #2
    1. Advertisements

  3. yesterday = datetime.date(today.year, today.month, today.day-1)
    Try writing it like this:
    2004-05-31

    Cheers,
    Brian
     
    Brian Quinlan, Jun 1, 2004
    #3
  4. thehaas

    thehaas Guest

    Except that it *does* work in other languages . . . that was part of
    my point. Here's a sample from some working Java code:

    // this works in January!
    Calendar now = Calendar.getInstance();
    Calendar lastmonth = Calendar.getInstance();
    lastmonth.set(now.get(Calendar.YEAR),
    now.get(Calendar.MONTH)-1,
    now.get(Calendar.DATE));
    Got it. Cool -- thanks.
     
    thehaas, Jun 1, 2004
    #4
  5. thehaas

    Yermat Guest

    I understand your felling but I really believe it SHOULD not go that way
    in other language... And so understand the python library point of view
    to be the better one.

    Anyway that's another debate ;-)
     
    Yermat, Jun 1, 2004
    #5
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.