c# - Difference between two months - only based on months and not date -


i using below code find month difference between 2 dates.

var watmonths = ((watinjenddate.year - waterstartdate.year) * 12) + watinjenddate.month - waterstartdate.month 

for example:

waterstartdate = 9/28/2015 waterinjenddate = 12/4/2015 

the answer above code 3. ultimate requirement "4" depicts months 9,10,11,12 waterstartdate in 9th month , enddate in 12th month of year.

what should modify in code?

in case, defining number of months between dates being inclusive of both month of start date , end date. number of months between 2015/1/1 , 2015/1/1 1. sure behavior want?

in order accomplish behavior described, add + 1 end of assignment.

var watmonths = ((watinjenddate.year - waterstartdate.year) * 12) +                      watinjenddate.month - waterstartdate.month + 1 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -