date issue

1. Senior Member
Join Date
Dec 1969
Posts
230

## date issue

How do I make sure that my start and end dates don&#039;t exceed 12 months? <BR><BR>if (start - end) &#062; 12 months<BR> then i adjust the end month to be exactly 12 months from start<BR><BR>e.g., if start = Jan 1, 2001, end = Jan 31, 2002 then <BR>end = Dec 31, 2001

2. ks
Senior Member
Join Date
Dec 1969
Posts
734

## RE: date issue

System.TimeSpan diff = end.Subtract(start);<BR>if (diff.Days &#062;= 365) {<BR> end = start.AddMonths(12);<BR>}<BR><BR>start and end must be instances of System.DateTime.<BR>

3. Senior Member
Join Date
Dec 1969
Posts
11,247

## What about leap year ? (eop)

.

4. ks
Senior Member
Join Date
Dec 1969
Posts
734

## I know this will come up

But this will work whether it is a leap year.<BR>For non leap year, the max allowable difference is 364 days and leap year 365 days.<BR>if (System.TimeSpan.Days &#062;= 365) works for both.<BR><BR>The original poster does not want start date + 12 months but start date + 12 month less 1 day.<BR>The End Day should be start.AddMonth(12) - 1 day<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•