Thread: Logic Question
View Single Post
  #2   Spotlight this post!  
Unread 11-03-2006, 11:06
evulish's Avatar
evulish evulish is offline
1010100
AKA: Grant Harding
#0084 (WATTNESS (bot: Chuck))
Team Role: Alumni
 
Join Date: Jul 2002
Location: Towanda/Wysox, PA
Posts: 1,434
evulish is just really niceevulish is just really niceevulish is just really niceevulish is just really nice
Send a message via AIM to evulish
Re: Logic Question

Is there any reason you can't store time() instead? If you need the d/m/y out of it later, you could use date() then.

Otherwise, the simplest way would be to use:

PHP Code:
if (strtotime("$itemE_month/$itemE_day/$itemE_year $itemE_hour:$itemE_minute $itemE_ampm") > time()) { echo "yup"; } 
It's more intensive than checking the logic but it's far simpler.

PHP Code:
if ($item_year $year) { echo "yes"; }
if (
$item_year == $year) {
  if (
$item_month $month) { echo "yes"; }
  elseif (
$item_month == $month) {
    if (
$item_day $day) { echo "yes"; }
    elseif (
$item_day == $day) {
      if (
$item_hour $hour) { echo "yes"; }
      elseif (
$item_hour == $hour) {
        if (
$item_minute $minute) { echo "yes"; }
      }
    }
  }

Another way would be:

PHP Code:
$old = array(
$item_year,
$item_month,
$item_day,
$item_hour,
$item_minute
);

$new = array(
$year,
$month,
$day,
$hour,
$minute
);

function 
compare_dates($old$new) {

for (
$i=0;$i<4;$i++){
if (
$old[$i] < $new[$i]) { return "no"; }
if (
$old[$i] > $new[$i]) { return "yes"; }
}

return 
"equal";
}

echo 
compare_dates($old$new); 
__________________
I'm a professional web developer. I'm good with PHP, Perl, Java/JSP, some RoR, XML, Javascript (AJAX as well), (x)HTML, CSS, etc.. Validated code is good; fully cross-browser code is better (you comply to your users and the software they use, not the other way around. Sorry!)

Last edited by evulish : 11-03-2006 at 11:13.