Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now