PHP Date function checking against mysql column of varchar

Discussion in 'PHP' started by new_to_php, Sep 6, 2011.

  1. #1
    I have a mysql database that has a column named datestamp which is varchar(30) and the values in this field are stored as a date example 09/06/2011
    Im trying to display data in the database only if the current date is equal to today's date. And im having some difficulties getting this to work. I was able to do this when i had the column set as a datetime but i do not like this column function there for i changed it. Any help that anyone can provide would be greatly appreciated.
    Im new to php and still have alot to learn.
    below is the php function that im trying to display.
    <?php
    $myDate = CURRENT('m/d/y');

    $result = mysql_query("SELECT * FROM eattendance WHERE datestamp = $myDate ");

    echo "<table border='1' align='center'>
    <tr>
    <th>Name</th>
    <th>Date Entered</th>
    <th>Entered By</th>
    <th>Reason</th>
    </tr>";
    .......more code ?>
    the rest of the code just displays the values from the database in the format of a table that is positioned in the middle of a php page.
     

    Attached Files:

    Solved! View solution.
    new_to_php, Sep 6, 2011 IP
  2. #2
    echo the value of $myDate and see what's really going into that variable.

    This works for me :

    $myDate = date("m/d/y"); 
    echo $myDate;
    
    $db = mysql_connect('localhost','user','pwd');
    mysql_select_db('test');
    $res = mysql_query("SELECT * FROM test WHERE datestamp='$myDate'");
    $row = mysql_fetch_array($res);
    PHP:
     
    shallowink, Sep 6, 2011 IP
  3. new_to_php

    new_to_php Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey shallowink,
    That work for me and believe it or not i had that originally but didn't realize that the dates in my database where set as 09/07/2011 and the $mydate value is using the format of 09/07/11
    so i appreciate your input and yeah probably would have caught that if my head wasn't so congested
     
    new_to_php, Sep 6, 2011 IP