How to do Excel date comparison

Hi,

I am trying to do a  date comparison in Excel 2010. I have a column of order dates. I am trying to determine if the order date is before 4/14/2014.  If column  A2 has an order date 6/10/2010 and I do the following formula in cell B2:   =A2<4/14/2014, I get FALSE.  If I change the formula in B2 to: = A2< Today()  I get TRUE. How can that be when both TODAY() and 4/14/2014 are both later than  6/10/2010?

Is this a date formatting issue?

Please advise.

Thanks!
Wm Allen SmithAsked:
Who is Participating?
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.

frankhelkCommented:
You have to convert your date into excel's internal date representation (float value, days since 01/01/1900 0:00am).

Either stuff that date into a cell value and refer to it in your formula or use a function for that, i.e. the DATE() function (refer to the help file for the exact syntax).
0
frankhelkCommented:
Addendum: The syntax is DATE(year, month, day), so your formula should  read
=A2<Date(2014, 4, 14)

Open in new window


For explanation of your mentioned results: The date 06/10/2010 (June 10, 2010) is internally represented as 40339 (0am, parts of the the day would be represented as fractions in an floating point number). 04/14/2014 (the date) would be represented as 41743. That way translated, the term =40339<41743 would correctly result in TRUE. The way you wrote the formula as =A2<4/14/2014 it would result in =40339<4/14/2014 (meaning 40339 less than 4 divided by 14 divided by 2014), resolved to =40339<0.000141864 (and that is defintely evaluated as FALSE).

Any questions left open ?
0
Rob HensonFinance AnalystCommented:
If you have the date hard coded in the formula it needs to be in double quotes:

 =A2<"4/14/2014"

However, it is safer to put in a cell and refer to cell instead as suggested above.

Thanks
Rob H
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Rob HensonFinance AnalystCommented:
If I change the formula in B2 to: = A2< Today()  I get TRUE. How can that be when both TODAY() and 4/14/2014 are both later than  6/10/2010?

TODAY() would result in 8/28/14 therefore 6/10/2010 is indeed less than (earlier than) TODAY.
0
frankhelkCommented:
If you have the date hard coded in the formula it needs to be in double quotes:
 =A2<"4/14/2014"
However, it is safer to put in a cell and refer to cell instead as suggested above.

I agree that it's safer with a cell, and it's safer with the DATE function. If you use the sheet in some Excel wher another date format is used, both cell and DATE() would still return the correct result. I would expect the version in quotes (which gives the date as string to Ecxcel and leaves it to the the date format rules to interpret it) to give a lot of hassle in that case (nasty behaviour of your sheet which is sometimes a pain in the a** to analyze and fix)
0
Rob HensonFinance AnalystCommented:
Other option would be to use DATEVALUE function:

=A2<DATEVALUE("4/14/2014")

But as frankhelk states, it still relies on date formatting on your system. I am in UK and using exactly as above does not recognise as a date because my system is expecting dd/mm/yy format.

Thanks
Rob H
0

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

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.