Check if date is next day

I've feeling this should be really obvious!

I have two dates. say date1, date2

How can I check if date2 is NEXT DAY of date1. so it ignores times
e.g.  if
date1 = 1/1/01 15:00
date2 = 2/1/01 12:00
result would give TRUE
rwallacejAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

try this sample

 DateTime date1 = Convert.ToDateTime("1/1/01 15:00");
            DateTime date2 = Convert.ToDateTime("2/1/01 12:00");
            if (date1.AddDays(1).Date == date2.Date)
            {
                // Yes, it's next day
            }
            else
            {
                //Not Next Day
            }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwallacejAuthor Commented:
I should say that the date1 and date2 objects are of type DATETIME
rwallacejAuthor Commented:
is you example here not creating datetime objects so in comparison it will have Time in it too???
Lokesh B RDeveloperCommented:
Hi,

Yes, If your date1 & date2 are of type DateTime then you can easily check the conditions.

In the above sample am comparing only DATE not the TIME.
ChloesDadCommented:
The date property of datetime object returns just the date part

You could also use the datediff function

result = (DateDiff(DateInterval.day, date1.date, date2.date) == 1)

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.