【问题标题】:insert current datetime to custom wordpress datetime column将当前日期时间插入到自定义 wordpress 日期时间列
【发布时间】:2019-11-02 22:40:53
【问题描述】:

我在将当前日期时间插入自定义 wordpress 日期时间列时遇到问题。我使用了curent_time 函数我还使用date('Y-m-d H:m:s') 作为列的值,但它不起作用。

如有任何建议,我将提供我的代码:

global $wpdb;
$load_rec_table = $wpdb->prefix.'load_rec';
// Insert into load record table
$wpdb->insert($load_rec_table,array(
    'rec_date' => current_time('mysql'),
    'total_load' => $_POST['totalPower'],
    'total_gap' => $_POST['totalGap'],
    'carriage' => $_POST['carriage']
    ));

【问题讨论】:

    标签: php mysql wordpress datetime


    【解决方案1】:

    可以使用 Mysq 的 NOW() 或 CURRENT_TIMESTAMP() 函数l

    global $wpdb;
    $load_rec_table = $wpdb->prefix.'load_rec';
    // Insert into load record table
    $wpdb->insert($load_rec_table,array(
        'rec_date' => NOW(),
        'total_load' => $_POST['totalPower'],
        'total_gap' => $_POST['totalGap'],
        'carriage' => $_POST['carriage']
        ));
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多