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
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.