rei Posted July 28, 2006 Share Posted July 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15866-comparison-of-date-with-php/ Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15866-comparison-of-date-with-php/#findComment-65050 Share on other sites More sharing options...
Ifa Posted July 28, 2006 Share Posted July 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15866-comparison-of-date-with-php/#findComment-65074 Share on other sites More sharing options...
rei Posted July 28, 2006 Author Share Posted July 28, 2006 thanks ifa and redarrowfound one way.put all the dates in an arraysort itand get the first and last element :) Quote Link to comment https://forums.phpfreaks.com/topic/15866-comparison-of-date-with-php/#findComment-65100 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.