|
-
Oct 16th, 2012, 03:06 AM
#1
Thread Starter
Addicted Member
how to calculate the difference between two dates to get in months.
I am using C# windows application
i have two datetimepicker, startdate and enddate.
the difference between the two datetime picker must be atleast one month.
just the difference between the two should be months(just like one month,2 months,..3...4 ..months).
when i select a date from the startdatepicker , the date on enddatepicker will automatically become the next month of the startdate and i can extend the enddate to other months.
@ any time the difference between the two dates should be full months( not 1/2 month or 2.5)
how can i do it please?
-
Oct 16th, 2012, 03:22 AM
#2
Re: how to calculate the difference between two dates to get in months.
Handle the ValueChanged event of the start date control and test whether it is Focused. If it is then you should update the Value of the end date control. Get the Value of both controls, which will be DateTimes. Get the Day of the start date and use the DateTime.DaysInMonth method to determine how many days are in the month of the currently selected end date. If the first is less than or equal to the second, set the day of the end date to match the start date, otherwise set the day of the end date to the last day of that month. You can then do the same thing with the two controls reversed.
Note that you will also need to ensure that the start date is never later then the end date.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|