SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy comparing dates - not working

    Hi,

    I'm trying to compare to dates/times. If one date is greater then the other, then it should do something. However it's not working.

    I have
    PHP Code:
     <?php
     
       
    //Check the close date of each job
       
    if ($current_date >= $closed_date) {
          
    $status "Closed";
          
         
    // Change the status in the DB to closed
         
    $sql "UPDATE jobs SET status = 0 where id = '$job_id'";
         
    $result = @mysql_query($sql,$db) or die(mysql_error());
          
       } else {
        
    $status "Open";
       }
     
    ?>
    No matter what the dates entered are, the status is always set to closed. As an example, I echo'd out the times I was comparing

    closed: 22 03 2003 : 17:00 PM
    current: 22 03 2003 : 14:18 PM

    obviously, 14:18pm is not greater then 17:00pm , so why isn't it working?
    coiL
    "cradled in the learning curve"

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what format are $current_date &&$closed_date in ?

    if they are unix timestamps then it should work if not then probably not , i.e. string comparison can work sometimes with dates and numbers but not always nor is it really supposed to.

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Funny it doesn't work, if the strings are in the format you posted.

    In any case, it's best to compare timestamps. You can use mktime() to convert your date to a UNIX timestamp for comparison purposes.


Bookmarks

Posting Permissions

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