Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem comparing 2 dates

    Hello

    I am having problems comparing two dates.

    I have this code

    PHP Code:
    <?php
    $exp_date
    ="22-01-2008";

    # creates Unix timestamp time for date('d-m-Y')
    $server_date=date('d-m-Y');
    $server_date_array=explode("-",$server_date);
    $server_date=mktime (0,0,0,$server_date_array[1],$server_date_array[0],$server_date_array[2],0);

    # creates Unix timestamp for  $exp_date
    $exp_date_stamp_array=explode("-",$exp_date);
    $exp_date_stamp=mktime (0,0,0,$exp_date_stamp_array[1],$exp_date_stamp_array[0],$exp_date_stamp_array[2],0);


    # compare Unix timestamp
    if ( $exp_date_stamp <= $server_date ) {
        echo 
    "EXPIRED" ;

        }
        else
    {
        echo 
    "VALID" ;
    }

    ?>


    It creates a Unix timestamp for date() and $exp_date
    then compare the 2 Unix timestamp to verifiy if $exp_date is valid or expired (compared with current date)

    It works on my computer without problems (returning VALID) .

    On some unix server where the server date was
    Tue Feb 27 01:56:46 WIT 2007

    the scripts returned EXPIRED instead of VALID .

    Anyone can tell me why ? What's wrong on my code ?

    Thank you!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Looks OK from here... what do you see when you echo all the variables?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •