Jump to content

comparison of date with PHP


rei

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
Link to comment
https://forums.phpfreaks.com/topic/15866-comparison-of-date-with-php/
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]
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

Archived

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

×
×
  • Create New...

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.