Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:21:35+00:00 2026-06-18T08:21:35+00:00

I have a the following code that runs fine with input format like {Year}/{Month}

  • 0

I have a the following code that runs fine with input format like {Year}/{Month} except when it comes to 1994/02

Here is the sample code

>>> import dateutil.parser as dtp
>>> dtp.parse('1994/01')
datetime.datetime(1994, 1, 29, 0, 0)
>>> dtp.parse('1994/03')
datetime.datetime(1994, 3, 29, 0, 0)
>>> dtp.parse('1994/02')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/antony/.virtualenvs/comp-invest/lib/python2.7/site-packages/dateutil/parser.py", line 720, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/Users/antony/.virtualenvs/comp-invest/lib/python2.7/site-packages/dateutil/parser.py", line 317, in parse
    ret = default.replace(**repl)
ValueError: day is out of range for month

As you can see, the code works fine with 1994/01 and 1994/03, but fails with 1994/02
Does this have anything to do with leap year? But more important, how do I get around this problem and make my code work again?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:21:36+00:00Added an answer on June 18, 2026 at 8:21 am

    dtp.parse is filling in the missing day with the current date’s day. You ran the code on 2013/01/29 and day 29 does not exist in February (i.e. 1994/02/29).

    Use this instead:

    dtp.parse('1994/01'+'/01')
    

    It will give consistent results (first day of month) regardless of when the code is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL code that runs against a Change Request database. Each
I have the below code that links and runs fine in 32bit mode -
I have some Fluent NHibernate code that runs fine on my local visual studio,
I have the following code which runs fine on my computer but fails online:
I have the following code which assembles and runs fine on Windows XP 32
I have some code that runs fine when I have a web proxy defined
I have the following table join that runs fine in Microsoft SQL Server and
I have the following code that runs on the CheckedChanged event of a checkbox.
Following code is pretty boiler plate code that runs fine as is, but when
I have the following XQUERY code in XMLSPY which runs fine. xquery version 1.0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.