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

  • Home
  • SEARCH
  • 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 7802777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:21:27+00:00 2026-06-02T01:21:27+00:00

What I would like to do is as follows Given two dates e.g. March

  • 0

What I would like to do is as follows

Given two dates e.g. March 02, 1998 and September 25, 2011. How to get split the interval into

  1. March 02, 1998 to March 31, 1998 ( 30 Days)
  2. April 01, 1998 to December 31, 1998 ( 9 Months)
  3. January 01, 1999 to December 31, 2010 ( 11 Years)
  4. January 01, 2011 to August31, 2011 ( 8 Months)
  5. September 01, 2011 to September 25, 2011 ( 30 Days)

    However if any of the interval doesn’t exist, we don’t wan to force include it i.e. the result will not always be days/months/years/months/days e.g.

    Given start date = ‘1998-02-01’ and end date = ‘2011-03-31’,
    The expect results is (Months/Years/Months)

    1998-02-01 ==> 1998-12-31
    1999-01-01 ==> 2010-12-31
    2011-01-01 ==> 2011-03-31

    Given start date = ‘1998-02-01’ and end date = ‘1998-03-31’,
    The expect results is (2 Months)

    1998-02-01 ==> 2011-03-31

    Given start date = ‘1998-01-05’ and end date = ‘1998-02-03’,
    The expect results is (Days/Days)
    1998-01-05 ==> 2011-01-31
    1998-02-01 ==> 2011-02-03

Have a look at the following in case my description does not make sense. I am trying to accomplish the same but in .net

Algorithm to find optimal day/month/year intervals to in an arbitrary timeframe?

  • 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-02T01:21:29+00:00Added an answer on June 2, 2026 at 1:21 am

    You can just do like this:

    DateTime startDate = new DateTime(1998, 3, 2);
    DateTime endDate = new DateTime(2011, 9, 25);
    
    DateTime firstMonth = new DateTime(startDate.Year, startDate.Month, 1).AddMonths(1);
    DateTime firstYear = new DateTime(startDate.Year + 1, 1, 1);
    DateTime lastYear = new DateTime(endDate.Year, 1, 1);
    DateTime lastMonth = new DateTime(endDate.Year, endDate.Month, 1);
    
    Console.WriteLine("{0:yyyy-MM-dd} - {1:yyyy-MM-dd}", startDate, firstMonth.AddDays(-1));
    Console.WriteLine("{0:yyyy-MM-dd} - {1:yyyy-MM-dd}", firstMonth, firstYear.AddDays(-1));
    Console.WriteLine("{0:yyyy-MM-dd} - {1:yyyy-MM-dd}", firstYear, lastYear.AddDays(-1));
    Console.WriteLine("{0:yyyy-MM-dd} - {1:yyyy-MM-dd}", lastYear, lastMonth.AddDays(-1));
    Console.WriteLine("{0:yyyy-MM-dd} - {1:yyyy-MM-dd}", lastMonth, endDate);
    

    Output:

    1998-03-02 - 1998-03-31
    1998-04-01 - 1998-12-31
    1999-01-01 - 2010-12-31
    2011-01-01 - 2011-08-31
    2011-09-01 - 2011-09-25
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to split a line such as: name1=value1,name2=value2, .....,namen=valuen two produce two
I have two classes that I would like to specify as follows: class Club
I would like to POST an entity as follows POST /example.org/MyEntity/100 Based on the
I need to process large image files into smaller image files. I would like
The documentation about List mention that itemTpl follows the XTemplate syntax. I would like
The problem I am facing is as follows: Given two polygons defining the borders
One of the things I would like to follow is to stick to the
I would like to do the follow redirection using htaccess: From: http://www.mywebsite.com/home/?page_id=273&mnth=8&yr=1993 To: http://www.mywebsite.com/
This is a follow-up question to the following if you would like to see:
Would like to be able to set colors of headings and such, different font

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.