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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:27:31+00:00 2026-05-17T06:27:31+00:00

I have a begin and start DateTime for a conversion that gets logged at

  • 0

I have a begin and start DateTime for a conversion that gets logged at the start and end of this event. I then generate a report that lists a bunch of information about the event including its runtime. I have a column for total time elapsed (in days) and a date representation of start and stop. Everything is in days, I don’t care about hours/minutes/seconds.

If the start time is 9/29/2010 and the end time is 9/31/2010 I want to print:

9/29-31/2010

If the start time is 9/29/2010 and the end time is 10/2/2010 I want to print:

9/29-10/2/2010

If the start time is 12/29/2010 and the end time is 1/2/2011 I want to print:

12/29/2010-1/2/2011

I know I can use the ToString(“M/d/yyyy”) method of datetime to print each individual date, but I’m hoping for an easy way to print two dates in a similar format.

  • 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-17T06:27:32+00:00Added an answer on May 17, 2026 at 6:27 am

    Your rules are pretty simple to translate to code, no need to get fancy.

    static string GetDateRangeString(DateTime startDate, DateTime endDate)
    {
        if (endDate.Year != startDate.Year)
        {
            return startDate.ToString("M/d/yyyy") + "-" + endDate.ToString("M/d/yyyy");
        }
        else if (endDate.Month != startDate.Month)
        {
            return startDate.ToString("M/d") + "-" + endDate.ToString("M/d/yyyy");
        }
        else
        {
            return startDate.ToString("M/d") + "-" + endDate.ToString("d/yyyy");
        }
    }
    

    Demos:

    Console.WriteLine(GetDateRangeString(new DateTime(2010, 9, 29), new DateTime(2010, 9, 30)));
    Console.WriteLine(GetDateRangeString(new DateTime(2010, 9, 29), new DateTime(2010, 10, 30)));
    Console.WriteLine(GetDateRangeString(new DateTime(2010, 9, 29), new DateTime(2011, 1, 30)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .Net service that has begun to refuse to start - the
Consider that I have a transaction: BEGIN TRANSACTION DECLARE MONEY @amount SELECT Amount AS
When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have
I have a table with start and finish datetimes that I need to determine
I have a SQL Server Stored Procedure that looks like this: CREATE PROCEDURE [dbo].[my_stored_procedure]
I have an input field that saves a URL, I'd like this saved input
Suppose I have this text to match: http://localhost:8080/start.jsp;jsessionid=9E4CDB636248C9610F57704E5E07F782?whatever=true&somethingelse=true Using this regular expression: ^(.*?start\.jsp)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$ The
I have CLI/MFC application and I would like to begin to learn how to
We have a company intranet with staff management functions. I would like to begin
I'm developing a website which to begin with will have three clear sub sites:

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.