c# - How can I split date range into months -


now many date range data(datatable) this:

startdate: enddate:

2016-06-12 2016-08-13

2016-01-12 2016-03-13

...

how can sum total days in each month in year? january november.

        datatable dtdaterange = ds1.tables[0];         //create months         int[] count = new int[12];         //loop data         (int = 0; < dtdaterange.rows.count; i++)         {             datetime starttime = ((datetime)dtdaterange.rows[i]["startdate"]);             datetime endtime = ((datetime)dtdaterange.rows[i]["enddate"]);              (int = starttime.dayofyear; < endtime.dayofyear; a++)             {                 count[starttime.month-1] = count[starttime.month-1] + 1;             }         }         foreach (int c in count)         {             console.writeline(c);         }          console.readkey(); 

maybe this. i've written in notepad i'm not sure compile. maybe you'll need fix here , there. can use list add dates loop container, if want.

        datetime startdate = datetime.parse("2016-06-12");         datetime enddate = datetime.parse("2016-08-13");          for(datetime date = startdate, startdate <= enddate, date = date.addmonths(1) )             console.writeline(date); 

and if need month of particular date can ask date via month property.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -