I have been looking through a bunch of different posts on here and on other sites for adding two dates together, but for some reason everyone wants to use ‘Now’
I would like to know how to add two different dates together when neither of which are now!
I have tried a few things but I am getting casting errors. Also worth noting I am setting it to the value of a dateTime picker on my page.
MaxDate.Value = MinDate.Value + TimeSpan.FromDays(1)
'does not work
MaxDate.Value = Now + TimeSpan.FromDays(1)
'does work!
If it is not obvious, I have two date pickers on my page and when a radio button is clicked I want to set the ‘End date’ (maxdate.value) to whatever the ‘Start date’ (mindate.value) is, and add one day to it.
Thanks for the help!
Just do this:
You don’t need create a
TimeSpanobject for that because theDatetype has built-in methods for doing incrementation by day, month, year, minute, etc.The
AddDaysmethod does not alter the original date, it just returns a newDateobject with the offset value.By the way, if you want to subtract a day, there is no
MinusDaysmethod, just dox.AddDays(-1).