Question

I am working on a chart that will plot the data points from 6 a.m. to 6 a.m. the next then repeat for the next day. The chart will plot from 6 am say today to 6 am tomorrow reset then start plotting for tomorrow's data.

Here is my variables

`DateTime startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 6, 0, 0);
DateTime EndDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); ( no good need it for next day at 6 am)

` How can I make my enddatetime variable for tomorrow at 6 am?

Was it helpful?

Solution

If I understood it correctly then it is as simple as:

DateTime startDateTime = DateTime.Today.AddHours(6); //DateTime.Today set to 6:00 AM
DateTime endDateTime = startDateTime.AddDays(1);

DateTime.Today will give you the current Date with time part set to 00:00:00, you can add 6 hours to it and that would give you current Date set to 6:00 AM. To get endDateTime you can add 1 day to your startDateTime.

If you want your endDateTime to be Current Day + 1 and time set to 5:59:59 then you can do:

DateTime endDateTime = startDateTime.AddDays(1).AddTicks(-1); //(most  accurate)

OTHER TIPS

 endDateTime = startDateTime.AddHours(24);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top