SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Comparing two strings, result is always true??

    I have the following code. All I am doing is comparing a string comparing todays date to another string containing a date. However, it always returns true, no matter which way I try to do it...

    Code:
    <?php
    ini_set("display_errors","1");
    ERROR_REPORTING(E_ALL);
    $today=date('d-M-Y');
    print "Variable Type TODAY:". gettype($today);
    
    while ($row = mysql_fetch_array($result)) {
    
    if($today == "14-JUN-2007") {
    print "Vacation ends today"; }
    
    }
    ?>
    I have verified that the variable data type is a string, I have tried many different comparison methods.. am i missing something obvious here? The value of $today is outputted as 14-Jun-2007.

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if($today == 14-JUN-2007) { 
    I take that you don't mean fourteen minus the (undefined) constant JUN, minus 2007? Because that's what it says.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, nevermind.. something i must of been missing before but i got it going... *slaps head*

  4. #4
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    PHP Code:
    if($today == 14-JUN-2007) { 
    I take that you don't mean fourteen minus the (undefined) constant JUN, minus 2007? Because that's what it says.

    Sorry, that was a typo. Should be quotations around it. I was comparing 2 identical variables, one of which I thought was picking up a value from a database but wasnt working properly..

    Stupid error on my part, would delete thread if I could.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tdob View Post
    Stupid error on my part, would delete thread if I could.
    Most errors are stupid, once you figure them out

    Next time, try to var_dump out the variables, in your code. That will often give you a very good idea of, what's wrong. It's easy to assume that a variable has a given value at a given point in your code, when in fact it it's something different.


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
  •