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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:21:48+00:00 2026-05-30T14:21:48+00:00

I am sure this has been done before so i am looking for an

  • 0

I am sure this has been done before so i am looking for an efficient solution instead of own custom solution.

Given 2 dates, I am trying to generate the accurate weekly date (for creating weekly orders).

EDIT: I need to use .NET standard library to do this.

Example below,

Given 28/02/2012 and 6/03/2012.

so, the weekly dates generated are
- Week From(Start Monday):   Week To(End Sunday):
- 27/02/2012               - 04/03/2012
- 05/03/2012               - 11/03/2012

Another example (1 month)

Given 01/02/2012 and 29/02/2012
so, the weekly dates generated are
- Week From(Start Monday):   Week To(End Sunday):
- 30/01/2012               - 05/02/2012
- 06/02/2012               - 12/02/2012
- 13/02/2012               - 19/02/2012
- 20/02/2012               - 26/02/2012
- 27/02/2012               - 04/03/2012

I am doing this in c#. Has this been done before? Mind sharing the solutions?

Cheers

  • 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-30T14:21:49+00:00Added an answer on May 30, 2026 at 2:21 pm

    Here’s a solution using Noda Time. Admittedly it requires a <= operator which I’m just implementing right now – but that shouldn’t take long 🙂

    using System;
    using NodaTime;
    
    class Test
    {
        static void Main()
        {
            ShowDates(new LocalDate(2012, 2, 28), new LocalDate(2012, 3, 6));
            ShowDates(new LocalDate(2012, 2, 1), new LocalDate(2012, 2, 29));
        }
    
        static void ShowDates(LocalDate start, LocalDate end)
        {
            // Previous is always strict - increment start so that
            // it *can* be the first day, then find the previous
            // Monday
            var current = start.PlusDays(1).Previous(IsoDayOfWeek.Monday);
            while (current <= end)
            {
                Console.WriteLine("{0} - {1}", current,
                                  current.Next(IsoDayOfWeek.Sunday));
                current = current.PlusWeeks(1);
            }
        }
    }
    

    Obviously it’s possible to do this in normal DateTime as well, but there’s no real representation of “just a date” which makes the code less clear – and you’d need to implement Previous yourself.

    EDIT: For example, in this case you might use:

    using System;
    
    class Test
    {
        static void Main()
        {
            ShowDates(new DateTime(2012, 2, 28), new DateTime(2012, 3, 6));
            ShowDates(new DateTime(2012, 2, 1), new DateTime(2012, 2, 29));
        }
    
        static void ShowDates(DateTime start, DateTime end)
        {
            // In DateTime, 0=Sunday
            var daysToSubtract = ((int) start.DayOfWeek + 6) % 7;
            var current = start.AddDays(-daysToSubtract);        
    
            while (current <= end)
            {
                Console.WriteLine("{0} - {1}", current, current.AddDays(6));
                current = current.AddDays(7);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this problem has been solved before and I'm curious how its done.
I'm not sure if this has even been done before, but what I am
I'm sure this has been asked before, but I can't find it. What are
I'm sure this has been answered before, but I really cannot find it. I
I'm sure this has been asked before, but I can't seem to find it
I'm sure this has been answered before, but I've spent the last three hours
Alright, I'm not sure if this question has been asked before so if it
sorry if this question has been asked before, I searched but wasn't sure on
I'm pretty sure this has been asked before but I can't seem to find
I'm sure this question has been asked before, but I'm too frustrated to find

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.