How can I get the maximum time of a DateTime value selected from datetimepicker? For example '08/21/2011 23:59:59'
myDateTime.AddDays(1).Date.AddSeconds(-1)
Update As per comments by @RenatoGama on the question:
One possible other answer specific to end date scenarios is myDateTime.Date.AddDays(1)
. which gets you the next day to end date, use <
instead of <=
(as in dateTocheck < endDate.Date.AddDays(1)
).
Sample:
'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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With