Solved

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

Posted on 2007-04-10
2
576 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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