Issue 1715302: datetime.date won't accept 08 or 09 as valid days. (original) (raw)

The method won't accept 08 or 09 as valid days, but will accept 07.

Here is my output:

Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import datetime t = datetime.date(2007, 05, 07) print t 2007-05-07 t = datetime.date(2007, 05, 08) File "", line 1 t = datetime.date(2007, 05, 08) ^ SyntaxError: invalid token t = datetime.date(2007, 05, 09) File "", line 1 t = datetime.date(2007, 05, 09) ^ SyntaxError: invalid token t = datetime.date(2007, 05, 10) print t 2007-05-10

I was able to reproduce this on another machine as well: Python 2.4.3 (#1, Aug 6 2006, 20:52:01) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

Recommend closing this as not a bug.

A number with a leading zero is interpreted as octal literal, so trying to interpret 08 gives an error, since anything bigger than 7 isn't allowed in octal numbers. For your examples above, you should do this:

t = datetime.date(2007, 5, 8) t = datetime.date(2007, 5, 9)

and then it works as expected.