Home All Groups Group Topic Archive Search About

Are they the same day?

Author
2 May 2007 9:25 PM
Andrew
Hello, friends,

What is the best way to test if two date values are the same day (same hour)
or not in c#.net?

As you know, in VB6, we have a fuction DateDiff("d", date1, date2). Do we
have a similar one in .net?

Thanks.

Author
2 May 2007 9:40 PM
Jon Skeet [C# MVP]
Andrew <And***@discussions.microsoft.com> wrote:
> What is the best way to test if two date values are the same day (same hour)
> or not in c#.net?

if (day1.Date==day2.Date)
{
    ...
}

and

if (day1.Date==day2.Date &&
    day1.TimeOfDay.Hours==day2.TimeOfDay.Hours)
{
    ...
}

--
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

AddThis Social Bookmark Button