Jump to content


Photo

comparison of date with PHP


  • Please log in to reply
3 replies to this topic

#1 rei

rei
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 July 2006 - 08:22 AM

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 = 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 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 08:37 AM

all posabiltys lol..........................

<?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";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 28 July 2006 - 09:54 AM

You know, if you use only one function etc after if, you don't need the { }.
<?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";
?>

Looks much neater in my eyes
I'm just a guy who likes to code for fun...

#4 rei

rei
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 July 2006 - 11:30 AM

thanks ifa and redarrow

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users