• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

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!
0
wasmithpfs
Asked:
wasmithpfs
  • 3
  • 3
6 Solutions
 
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 HensonIT & Database AssistantCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Rob HensonIT & Database AssistantCommented:
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 HensonIT & Database AssistantCommented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now