Solved

Display 1st value and last Date value from an Array in C#

Posted on 2007-04-10
2
574 Views
Last Modified: 2007-12-19
Dear experts,

I am displaying dates from the array as shown as below:

             foreach (Day d in days)
            {
                DateTime h = new DateTime(d.date.Year, d.date.Month, d.date.Day, 0, 0, 0);
                output.Write(h.ToString("D"));  
            }

This is Displaying dates as shown as below:
4/9/2007            4/10/2007     4/11/2007       4/12/2007        4/13/2007    

Instead is there a way I can just display something like this:
April 9 2007- April 13 2007

Please help
0
Comment
Question by:rowmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 500 total points
ID: 18887127
Assuming that the "days" are contiguous:

DateTime startDate = new DateTime(days[0].date.Year, days[0].date.Month, days[0].date.Day, 0, 0, 0);
DateTime endDate = new DateTime(days[days.Length()-1].date.Year, days[days.Length()-1].date.Month, days[days.Length()-1].date.Day, 0, 0, 0);
output.Write(startDate.ToString("D") + " - " + endDate.ToString("D"));
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 18887129
           foreach (Day d in days)
            {
                DateTime h = new DateTime(d.date.Year, d.date.Month, d.date.Day, 0, 0, 0);
                output.Write(h.ToString("MMMM dd yyyy"));  
            }
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question