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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:56:44+00:00 2026-05-27T19:56:44+00:00

This is a bit difficult to explain, so I apologize if this doesn’t make

  • 0

This is a bit difficult to explain, so I apologize if this doesn’t make much sense.

I have a program where I am doing some scheduling. One of the settings it has is to run a task weekly on certain days. For example, weekly on Monday, Wednesday and Friday.

Consider the example where the current task is scheduled for 1/2/2012, which is a Monday, I already have a bunch of code working to the point where I know the next task run should be on the wednesday following 1/2/2012. All I need to do is calculate the actual date of that Wednesday (1/4/2012).

I actually have the day of the week as the corresponding integer from date.weekday(), so in this case I have 2 which represents wednesday.

Whats the best way to handle something like this? I feel like there should be a fairly simple solution, but it isn’t coming to mind. I was thinking of using a calendar object to search through to find the day of the week I want, but that seems like overkill.

  • 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-05-27T19:56:45+00:00Added an answer on May 27, 2026 at 7:56 pm

    Use a timedelta to add to a date. For example, using some date d as the scheduled date for a current task, and some day next_day (the next day you’d like to run the task).

    from datetime import date, timedelta
    ...
    n = (next_day - d.weekday()) % 7 # mod-7 ensures we don't go backward in time
    next_run_date = d + timedelta(days=n)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a bit difficult to explain but I have two columns in
I have this problem which i find a bit difficult to explain but I
This one is a bit tricky to explain. I have a usercontrol with some
This might be a bit difficult to explain in writing, so please bear with
This will be a bit difficult to explain but I will try my best.
It might be a bit difficult to explain, so I'll give some example code.
This is a bit of a difficult problem to explain, but I'm hoping it
Not sure if this has been asked before, it's a bit difficult to explain.
This is very specific, and a bit difficult to explain, and quite likely impossible,
This is a bit difficult to explain, so please bear with me. I am

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.