ASP .NET C# Show Only Hourly DateTime values from an Array of 24 hour values.

Asp .net C#. Show only date/time values from a 24 hour period which are 3 hours apart. In the following code, dayArray has 360 date/time values. Each value is 4 minutes apart from the other ones. You can see the output of Response.Write in the following page:

So how I do I just show DateTime values like starting from the very first DateTime value to the next 1 hour DateTime value, and then the next 1 hour, until the end of all 24 hour values?

string[] dayArray = formatData.ToString().Split(new char[] { ',' });//split to create array
                             for (int i = 0; i < (dayArray.Length - 1); i++)
                    DateTime curTime = Convert.ToDateTime(dayArray[i]);
                    DateTime displayTime = curTime.AddHours(3);
                    Response.Write(curTime + "<BR>");
                  //will show the ouput as //in
Who is Participating?
Elvio LujanConnect With a Mentor .Net Senior DeveloperCommented:
something like this???
DateTime d = DateTime.Now;
                for (int i = 0; 24-d.Hour; i++)
                    Response.Write(d.ToString()+ "<BR>");
                  //will show the ouput as //in
irfantakAuthor Commented:
Thanks. Nah, not sure what your code is--DateTime.Now does not apply to my code--there is already a set of Date/Time values spanning 24 hours.. Okay, here is the current online output:

and the code is

 string[] dayArray = formatData.ToString().Split(new char[] { ',' });
                for (int i = 0; i < (dayArray.Length - 1); i++)//because of the extra , at the end, loop to one less
                    DateTime curTime = Convert.ToDateTime(dayArray[i]);
                    Response.Write(curTime + "<br>");

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.