How to fix my date problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    How to fix my date problem

    the code below is met to insert the variable u_date to my table and echo it but when ever i echo the date from the table i select it, it's not also correct ever when my system date is correct and secondly i want the date should look like this 10-June-2010 not like this 10-6-2010.

    Code:
    $name= ($_POST['name']);
    $u_date = date ('h.m.Y');
    
    mysql_query("INSERT INTO user
    (name, u_date) VALUES('" . $name . "', '" . $u_date. "')
    
    i select the date from user and echo but the date is not correct
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    mySQL date format is yyyy-mm-dd. You must insert it this way.

    How you want to display it, that's another story. Database is for storage, not for display.

    What's your table definition like? is it a varchar or datetime?

    i select the date from user and echo but the date is not correct
    That doesn't tell me much. Where's the code? what's not correct about it? how much is it off by?


    Dan

    Comment

    • simon2x1
      New Member
      • Dec 2008
      • 123

      #3
      what i want is this the date variable which i insert and select back in my table to echo should display the correct date like today date is 2005-10-27 when i insert the variable date and select to echo it display this 2012-10-20 also my U_date field i choose date for the type lastly how can i make the date to look like this 10-June-2010 not like this 10-6-2010
      Code:
       $name= ($_POST['name']);
       $u_date = date ('h.m.Y');
        
       mysql_query("INSERT INTO user
       (name, u_date) VALUES('" . $name . "', '" . $u_date. "')
      
      $query1 = "SELECT * FROM user";
      $result1 = mysql_query ($query1) or die('query error');
      $line = mysql_fetch_assoc($result1);
      
      $d_user = $line[name];
      $d_date = $line[u_date];
      
      echo"$d_user<br>$d_date";

      Comment

      • simon2x1
        New Member
        • Dec 2008
        • 123

        #4
        what i want is this the date variable which i insert and select back in my table to echo should display the correct date like today date is 2005-10-27 when i insert the variable date and select to echo it display this 2012-10-20 also my U_date field i choose date for the type lastly how can i make the date to look like this 10-June-2010 not like this 10-6-2010
        Code:
         $name= ($_POST['name']);
         $u_date = date ('h.m.Y');
          
         mysql_query("INSERT INTO user
         (name, u_date) VALUES('" . $name . "', '" . $u_date. "')
        
        $query1 = "SELECT * FROM user";
        $result1 = mysql_query ($query1) or die('query error');
        $line = mysql_fetch_assoc($result1);
        
        $d_user = $line[name];
        $d_date = $line[u_date];
        
        echo"$d_user<br>$d_date";

        Comment

        Working...