Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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