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 8902113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:31:53+00:00 2026-06-15T01:31:53+00:00

I have code like this: import time from datetime import date startyear = raw_input("start

  • 0

I have code like this:

import time
from datetime import date

startyear = raw_input("start year: ")
startmonth = raw_input("start month: ")
startday = raw_input("start day: ")
endyear = raw_input("end year: ")
endmonth = raw_input("end month: ")
endday = raw_input("end day: ")

startdate = date(int(startyear), int(startmonth), int(startday))
while startdate < date(int(endyear), int(endmonth), int(endday)):
    print startdate
    startdate = startdate.replace(day=startdate.day + 1)

This code:

  1. gets the start and end date by manual input
  2. generate a list of dates between them

But the problem is, if I set up the date like, for example,

startdate: 2012-10-28
enddate: 2012-11-4

the output would be like:

2012-10-28
2012-10-29
2012-10-30
2012-10-31
ValueError: day is out of range for month

I want the output to be like:

2012-10-28
2012-10-29
2012-10-30
2012-10-31
2012-11-01
2012-11-02
2012-11-03
2012-11-04

So I want the dates to go through month. How can I do it?

  • 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-15T01:31:55+00:00Added an answer on June 15, 2026 at 1:31 am

    Instead of startdate.replace(), you should use timedelta…

    from datetime import date, timedelta
    # Get input here...
    while startdate < date(int(endyear), int(endmonth), int(endday)):
        print startdate
        startdate += timedelta(days=1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which, in a simplified form, looks like this: from tornado import
I have this code here import subprocess from time import strftime # Load just
I have some code like: import math, csv, sys, re, time, datetime, pickle, os,
Let's say I have some code (using CherryPy) that looks like this: import cherrypy
I have seen in some source code (by other developers) something like this: #import
I have a go program like this, package main import fmt import time func
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code like this - (IBAction)onClick:(id)sender { NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:)
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have code like this: ... entry.KeyPressEvent += EntryKeyPressEvent; ... } void EntryKeyPressEvent(object o,

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.