|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Comparing datesI need to be able to compare to dates to ensure that one is at least 1 day greater than the other. Im trying to do if(toDate !> fromDate){ // handle } This works but the problem is its comparing the datetime down to the minute and second. I need to be accurate only to the date. Otherwise, a comparison for two datetimes that are within the same date, but of different times will give a false positive. Can anyone tell me how to ensure that one datetime is at least one day greater than the other? Many thanks Simon Hello, Simon!
one way DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; dt2 = dt2.AddDays(2); TimeSpan span = dt2 - dt1; if ( span.Days > 1 ) else another one or you can use DateTime.DayOfWeek or Day, or DayOfYear dependin on the scope of dates being compared Simon Harvey <notha***@hotmail.com> wrote:
Show quote > I need to be able to compare to dates to ensure that one is at least 1 day if (toDate.Date > fromDate.Date)> greater than the other. > > Im trying to do > > if(toDate !> fromDate){ > // handle > } > > This works but the problem is its comparing the datetime down to the minute > and second. I need to be accurate only to the date. Otherwise, a comparison > for two datetimes that are within the same date, but of different times will > give a false positive. > > Can anyone tell me how to ensure that one datetime is at least one day greater > than the other? { ... } -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||