Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    30

    Unanswered: comparison of date with PHP

    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:
    Code:
    $earliest = XXX($row[date1], $row[date2], $row[date3])  <- returns ("2006-06-01")
    
    $latest = XXX($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 XXXXX(date1,date2,date3) <--returns '2006-06-01 '
    select YYYYY(date1,date2,date3) <--returns '2006-09-19 '

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    In mysql, take a look at the GREATEST(value1,value2,...) and LEAST(value1,value2,...) functions.

    In PHP, use the MIN(...) and MAX(...) functions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •