How to compare between mysql datetime field DateStart and DateEnd?

Hello guys!
I need your help.

I have two fields date in my table MYSQL:

  1. Field DateStart 2012-05-01 12:00:00;
  2. Field DateEnd 2012-05-05 12:00:00

I need extract in output the greater of the two dates, in this example 2012-05-05 12:00:00.

Thank you for the suggestion.

SELECT IF (DateStart > DateEnd, DateStart, DateEnd) AS GreaterDate FROM TABLE

thanks a lot!

SELECT GREATEST(DateStart,DateEnd) AS GreaterDate FROM daTable


I just learned something new. Didn’t realize that existed in MySQL.

Great, thanks a lot!

mysql> SELECT
	GREATEST(DateStart, DateEnd) AS GreaterDate
| GreaterDate         |
| 2012-05-05 12:00:00 |
1 row in set