How do I insert a date into mysql as a parameter?

后端 未结 2 1788
既然无缘
既然无缘 2021-01-21 18:38

I have the following code:

function dbInsert()
{
    global $dbcon, $dbtable;
    global $inputData;

    $sqlQuery = \'INSERT INTO \' . $dbtable . \' (id_author         


        
相关标签:
2条回答
  • 2021-01-21 19:18

    You can use a date/time column

    http://dev.mysql.com/doc/refman/5.1/en/date-and-time-types.html

    and use the STR_TO_DATE function:

    http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date

    Or you can convert it to a unix timestamp and insert this one in an INT Column.

    0 讨论(0)
  • 2021-01-21 19:19

    You could take a look at the STR_TO_DATE function. It takes a format parameter. The allowed values for the format parameter are described here.

    $sqlQuery = 'INSERT INTO ' . $dbtable . ' (id_author, date, title, description)' .
                ' VALUES (?, STR_TO_DATE(?, \'%d.%m.%Y\'), ?, ?)';
    
    0 讨论(0)
提交回复
热议问题