Fetching data from STR_TO_DATE

Discussion in 'PHP' started by yoda69, Nov 24, 2009.

  1. #1
    Hi,
    I'm sending some information to mysql server to format a string into datetime format that the server can understand. I'm running into problems regarding fetching that data.

    
    $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
          mysql_select_db(DB_NAME, $connection) or die(mysql_error());
    $newSqlDate = "SELECT STR_TO_DATE('$newDateTime', '%m/%d/%Y %h,%i,%p');"; 
      $result = mysql_query($newSqlDate);
    $row = mysql_fetch_array($result) or die(mysql_error());
      echo "Date and Time: ".$row['datetime'];
    mysql_close($connection);
    
    PHP:
    My echo returns nothing besides "Date and Time"

    Thanks
     
    yoda69, Nov 24, 2009 IP
  2. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Try
    
    $newSqlDate = "SELECT STR_TO_DATE('$newDateTime', '%m/%d/%Y %h,%i,%p') as `datetime`";
    
    PHP:
    It may help.
     
    stOK, Nov 24, 2009 IP
  3. yoda69

    yoda69 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes your solution worked. Thanks!
     
    yoda69, Nov 24, 2009 IP