myDateTime.AddDays(1).Date.AddSeconds(-1)
Update According to @RenatoGama's comments on the question:
One possible other answer specific to end date scripts is myDateTime.Date.AddDays(1) . which gets you the day before the end date, use < instead of <= (as in dateTocheck < endDate.Date.AddDays(1) ).
Example:
'08 / 21/2011 13:03:59 '-> .AddDays (1) -> '08 / 22/2011 13:03:59'
'08 / 22/2011 13:03:59 '-> .Date -> '08 / 22/2011 00:00:00'
'08 / 22/2011 00:00:00 '-> .AddSeconds (-1) -> '08 / 21/2011 23:59:59'
// OR
'08 / 22/2011 00:00:00 '-> .AddTicks (-1) -> '08 / 21/2011 23:59:59'
// Note: A tick is the smallest unit for time difference that DateTime can detect
// So, technically more accurate answer than using seconds - Thanks @aron
Note: AFAIK, '08 / 22/2011 '== '08 / 22/2011 00:00:00'
source share