Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Website Design/Showcase (http://www.chiefdelphi.com/forums/forumdisplay.php?f=64)
-   -   Logic Question (http://www.chiefdelphi.com/forums/showthread.php?t=45260)

aubinhick990 10-03-2006 22:28

Logic Question
 
This is a PHP website....

Okay, I have these variables...
PHP Code:

$itemE_year
    $itemE_month
    $itemE_day
    $itemE_hour
    $itemE_minute
    $itemE_ampm

    $year 
date("Y");
    
$month date("m");
    
$day date("d");
    
    
$hour date("h");
    
$minute date("i");
    
$ampm date("A"); 

Basically they're self-explanatory....the $itemE_x is just a number being assigned via the contents of a text file.

Now, my question is what logic would I need if I wanted to check if the Item's year/month/day and hour/minute has passed my server's year/month/day, hour/minute.

This is the logic I've come up with but it doesn't work quite right...

PHP Code:

if(  (($year >= $itemE_year)) )
{

    if(
$month == $itemE_month)
    {
      if(
$day >= $itemE_day)
         {
        
$DISPBOX "false";
        echo 
"Time has passed!";
         }
    } 

    if( ((
$hour >= $itemE_hour) and ($minute >= $itemE_minute)) and ($ampm == $itemE_ampm) )
{
Whatever else I'm doing....


Any suggestions? Thanks a ton!

evulish 11-03-2006 11:06

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); 


aubinhick990 11-03-2006 16:45

Re: Logic Question
 
Wow thanks a lot. I can't do it right now but I'll work on that ASAP and get back to you about how it goes. As you can tell, I'm pretty novice when it comes to PHP but am still learning.


All times are GMT -5. The time now is 06:25.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi