javascript - how to get the week number from two start and end custom dates in asp.net/c# -
for example have start date = 05-09-2016(dd-mm-yyyy) , end date = 09-01-2017
and want have week starting 5th sep called week 1 , last week 18
edit: shall giving date , these 2 start , end dates should give me week number. eg. when enter 09-11-2016 should give me week 6
and have acheive without doing hardcoding.
uptil have written
datetime date = new datetime(2016, 09, 05 ); datetimeformatinfo dfi = datetimeformatinfo.currentinfo; calendar cal = dfi.calendar; console.writeline( (cal.getweekofyear(date, dfi.calendarweekrule, dfi.firstdayofweek))-36);
but doesn't work when new year starts .. advice please? tell if can acheive similar using javascript if not acheivable in asp.net/ c#
it looks need calculate number of weeks between 2 dates, please give try below:
this prints 18
expected.
datetime date1 = new datetime(2016, 09, 05); datetime date2 = new datetime(2017, 01, 09); var weeks = math.ceil((date2 - date1).totaldays / 7); console.writeline(weeks);
Comments
Post a Comment