c# - Generate Date Time offset -
i have datetimeoffset input param. need create other datetimeoffset param month 2 month less input:
//datetimeoffset input; datetimeoffset modified = new datetimeoffset(input.year, input.month - 2, input.day, input.hour, input.minute, input.second, input.millisecond, input.offset); exception
year, month, , day parameters describe un-representable datetime.
what wrong? - month 4. s0 4-2 = 2 valid thanks
i think month red herring, it's more day above 28 means trying create date 30th feb (which doesn't exist!).
use addmonths method instead
datetimeoffset modified = input.addmonths(-2);
Comments
Post a Comment