Am I asking too much from datetime?

T

thehaas

-----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
(e-mail address removed)
http://www.binary.net/thehaas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAvGe4aP33v4T41CURAkQGAKChO0yxPDxHwXHTsNOb0eO92zECGgCdHKZ2
Irj6f33KpdXvwxsIhkM+Bo8=
=IRWr
-----END PGP SIGNATURE-----
 
Y

Yermat

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?

Of course it does not work !
0 is not a valid day...
You should do something like:
2004-05-31
 
B

Brian Quinlan

yesterday = datetime.date(today.year, today.month, today.day-1)
Is this is a bug, or outside of the functionality of datetime?

Try writing it like this:
2004-05-31

Cheers,
Brian
 
T

thehaas

Yermat said:
Of course it does not work !
0 is not a valid day...
You should do something like:

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));
2004-05-31

Got it. Cool -- thanks.
 
Y

Yermat

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

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 ;-)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top