Forum Moderators: coopster

Message Too Old, No Replies

comparison of date with PHP

         

rei15

8:23 am on Jul 28, 2006 (gmt 0)

10+ Year Member



is there anyway i can compare 3 or more date type column?

let's say i have
------------------------------------------------
date1 ¦ date2 ¦ date3
------------------------------------------------
2006-06-01 ¦ 2006-06-15 ¦ 2006-09-19
------------------------------------------------

and my select statement returns this 3 value.

is there any way i can write in PHP to get the earliest or the latest date?
let's say:


$earliest = #*$!($row[date1], $row[date2], $row[date3]) <- returns ("2006-06-01")

$latest = #*$!($row[date1], $row[date2], $row[date3]) <- returns ("2006-09-19")

i tried to get these from mysql command like if possible but cant find any way to do it..
i guess there's no function to this..
select #*$!XX(date1,date2,date3) <--returns '2006-06-01 '
select YYYYY(date1,date2,date3) <--returns '2006-09-19

madpenguin2

5:16 am on Jul 29, 2006 (gmt 0)

10+ Year Member



i would think select max(date1,date2,date3) or min would work... But, then again. i didn't try it...

coopster

2:12 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



LEAST and GREATEST comparison function operators [dev.mysql.com] might me another option.