Jump to content

Archived

This topic is now archived and is closed to further replies.

rei

comparison of date with PHP

Recommended Posts

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")
[/code]

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

Share this post


Link to post
Share on other sites
all posabiltys lol..........................

[code]
<?php

$date1="10-01-2006";
$date2="11-01-2006";
$date3="09-01-2006";

if($date1>$date2){

echo"a";

}elseif($date2>$date1) {

echo"b";

}elseif($date1<$date2) {

echo"c";

}elseif($date2<$date1) {

echo"d";

}elseif($date2>$date1) {

echo"e";

}elseif($date3>$date1) {

echo"f";

}elseif($date3<$date1) {

echo"g";

}elseif($date3>$date2) {

echo"h";
}elseif($date2<$date2) {

echo"i";
}
?>
[/code]

Share this post


Link to post
Share on other sites
You know, if you use only one function etc after if, you don't need the { }.
[code]<?php

$date1="10-01-2006";
$date2="11-01-2006";
$date3="09-01-2006";

if($date1>$date2) echo"a";

elseif($date2>$date1) echo"b";

elseif($date1<$date2) echo"c";

elseif($date2<$date1) echo"d";

elseif($date2>$date1) echo"e";

elseif($date3>$date1) echo"f";

elseif($date3<$date1) echo"g";

elseif($date3>$date2) echo"h";

elseif($date2<$date2) echo"i";
?>[/code]

Looks much neater in my eyes

Share this post


Link to post
Share on other sites
thanks ifa and redarrow

found one way.
put all the dates in an array
sort it
and get the first and last element :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.