Thread: Comparing dates

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    15
    Rep Power
    0
    Hi there, just wondering if you guys could help me with a little problem? Basically I have a PHP script taking the input string $passeddate (in the format YYYY-MM-DD) and using a MySQL query to compare with an item of DATE type in my table.. trouble is it's not really giving me any answers.. the bloody thing's driving me nuts.. any ideas?

    Cheers,

    Ryan

    PS Sorry for yet another thick question!
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    You should be able to compare date columns with that format. can you post some of your code, maybe your missing something?

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    15
    Rep Power
    0
    Thanks for replying.. ok well here it is..

    $query=("SELECT * FROM entries WHERE date<$passeddate");
    $result=mysql_query($query);

    The user input is YYYY-MM-DD (nice and easy for MySQL) and is stored at $passeddate. I've confirmed it is passed by a quick print ("$passeddate"); and it's working fine.. just not pulling up any records.. no error messages or anything so the syntax is fine..

    I appreciate any help anyone can offer me on this matter! Cheers,

    Ryan
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    Put single quotes around $passdate. You have to put quotes around anything that's not an integer.

    $query=("SELECT * FROM entries WHERE date<'$passeddate'");
    $result=mysql_query($query);

    ---John Holmes...
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    15
    Rep Power
    0
    Thanks for the help.. bloody thing's still not working.. gonna throw this bloody computer out the window in a minute!

    I've checked that the date is passed in the right format and it is.. i really can't figure out where I'm going wrong.. i'm at screaming point!!!

    the full code is as follows..

    <?


    //HTML Header
    include ("header.txt");

    //Variable Definition
    $server="localhost";
    $uid="CENSORED";
    $pwd="CENSORED";
    $message=file('message.txt');

    //Connect To MySQL
    mysql_connect($server, $uid, $pwd) or die ('something went wrong in connect stage');


    //Pick a database.. any database..
    mysql_select_db ('companies') or die ('Something went wrong in the select database stage');


    $query=("SELECT * FROM entries WHERE date<'$passeddate'");
    $result=mysql_query($query);

    // How many records match this query?
    $number=MYSQL_NUMROWS($result);
    $arse=$passeddate;
    print "$passeddate";

    $i = 0;
    print "Record numbers ";
    WHILE ('$i'<'$count'){
    $recno=mysql_result($result,'$i','recno');
    print "<A HREF=../display.php?recno=$i>$i</A> and ";
    $i++;
    }
    print " require reminding.";

    // Do Mailing in command below
    // mail ('$email',"subject",$message);

    include ("footer.txt");
    ?>

    Anything obvious that I've f***ed up there?

    Cheers,

    Ryan
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    15
    Rep Power
    0
    Please someone help!!! I'm desperate!!!! AAAAAAAAARGH!
  12. #7
  13. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    $i = 0;
    print "Record numbers ";
    WHILE ('$i'<'$count'){
    $recno=mysql_result($result,'$i','recno');
    print "<A HREF=../display.php?recno=$i>$i</A> and ";
    $i++;
    }


    That part is messing me up. Don't put single quotes around variables. PHP will not evaluate variables within single quotes....

    $i = 0;
    print "Record numbers ";
    WHILE ($i<$count){
    $recno=mysql_result($result,$i,"recno");
    print "<A HREF=../display.php?recno=$i>$i</A> and ";
    $i++;
    }

    Plus, you never define what $count is, and you never use $recno. What is the good of getting it from the database if you never use it. Maybe your logic is messed up?

    Try the above code and tell me what errors you get.

    ---John Holmes...
  14. #8
  15. Lurker - in your bushes
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    .be
    Posts
    494
    Rep Power
    117
    $query=("SELECT * FROM entries WHERE date<'$passeddate'");
    $result=mysql_query($query);


    Try :

    $query = "SELECT * FROM entries WHERE date < '$passeddate'";

    $result=mysql_query($query);



    ------------------
    Alain
    Aka "Saintaw"

Similar Threads

  1. Replies: 8
    Last Post: September 4th, 2003, 10:22 AM
  2. ASP - SQL comparing dates - plz HELP!
    By davidagnew in forum ASP Programming
    Replies: 1
    Last Post: September 1st, 2003, 03:57 PM
  3. SQL Comparing dates prob in ASP
    By davidagnew in forum MS SQL Development
    Replies: 1
    Last Post: September 1st, 2003, 03:39 PM
  4. comparing two dates
    By php_2003 in forum PHP Development
    Replies: 2
    Last Post: July 5th, 2003, 02:19 PM
  5. Comparing mysql type dates?
    By Saus in forum PHP Development
    Replies: 4
    Last Post: May 16th, 2003, 10:12 AM

IMN logo majestic logo threadwatch logo seochat tools logo