Results 1 to 6 of 6

Thread: Date Format

  1. #1
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109

    Unanswered: Date Format

    I want to insert in a value using php but some problem
    in it's sql query

    insert into school.std_info values('7','std','sd','2323','mj','234','sadf23',D ATE_FORMAT('17-11-1990','%d-%m-%Y'),'male','234234','234234','2010-06-09','22','10')

    this is the mysql query giving me error when i direct put in mysql
    PHP Code:

    #1136 - Column count doesn't match value count at row 1

    INSERT INTO school.std_info
    VALUES 
    (
    '7''std''sd''2323''mj''234''sadf23'DATE_FORMAT'17-11-1990''%d-%m-%Y' ) , 'male''234234''234234''2010-06-09''22''10'

    PHP Code:
    stnd_code int(11)   
      
    stnd_fcode int(11)                
      
    stnd_name varchar(50
      
    stnd_fname varchar(50)
      
    stnd_fnic varchar(25)
      
    stnd_mname varchar(50)
      
    stnd_mnic varchar(25
      
    stnd_add varchar(100
      
    stnd_dob date
      stnd_gender varchar
    (6)
      
    stnd_ph int(11)                
      
    stnd_mob int(11
     
    stnd_jdate date 
      stnd_fees int
    (5)  
      
    stnd_class varchar(10
    table structure

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by don_log View Post
    but some problem
    do you see what the problem is? you have 15 columns in the table, but you are supplying only 14 values, therefore the error is "Column count doesn't match value count"

    by the way, that DATE_FORMAT function call will ~not~ do what you expect -- use the STR_TO_DATE function instead
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    it insert this function date in null

    NULL show in row

    when i insert and browse the table

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    mysql expects dates in ISO format YYYY/MM/DD, or YYYY-MM-DD or some other year month day styling
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    which is what the STR_TO_DATE function accomplishes

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jun 2010
    Posts
    6
    The default way to store a date in MySQL is with the type DATE. Below is the proper format of a DATE.
    - YYYY-MM-DD
    - Date Range: 1000-01-01 to 9999-12-31

    INSERT INTO dateplayground (dp_name, dp_date) VALUES ('DATE: Manual Date', '2020-2-14')
    Below is a quick script that will spit out the MySQL table dateplayground in HTML.
    PHP Code:
    <?php
    $query 
    "SELECT * FROM dateplayground";
    $result mysql_query($query) or die(mysql_error());

    echo 
    "<table border='1'><tr>";
    for(
    $i 0$i mysql_num_fields($result); $i++){
        echo 
    "<th>".mysql_field_name($result$i)."</th>";
    }
    echo 
    "</tr>";
    while(
    $row mysql_fetch_array($result)){
        echo 
    "<tr>";
        for(
    $i 0$i mysql_num_fields($result); $i++){
            echo 
    "<td>"$row[$i] ."</td>";
        }
        echo 
    "</tr>";
    }

    echo 
    "</table>";

    ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •