首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >时间戳列中的Wordpress insert NOW()返回全零

问时间戳列中的Wordpress insert NOW()返回全零
EN

Stack Overflow用户
提问于 2014-07-20 19:20:05
回答 2查看 1.6K关注 0票数 1

我想在我的列的时间戳列中插入一个时间戳,但我总是得到全零。

下面是我的插图:

代码语言:javascript
复制
$now = 'NOW()';

// insert the date into the db
 $wpdb->insert( 
    'wp_date', 
    array(
        'name' => $name,
        'date' => $now    
    ), 
    array( 
        '%s',
        '%s'
    ) 
); // end insert
EN

回答 2

Stack Overflow用户

发布于 2014-07-20 19:28:27

尝试使用current_time,如下所示(我认为这是一个很好的替代方案):

代码语言:javascript
复制
$now = current_time('mysql');

// insert the date into the db
 $wpdb->insert( 
    'wp_date', 
    array(
        'name' => $name,
        'date' => $now    
    ), 
    array( 
        '%s',
        '%s'
    ) 
); // end insert

因此,current_time参数" mysql“表示使用mysql时间戳格式。

票数 3
EN

Stack Overflow用户

发布于 2017-02-07 16:33:28

函数current_time('mysql');返回博客的时间,而不是mysql服务器的时间。要获取Mysql服务器的时间,请执行以下操作。

代码语言:javascript
复制
global $wpdb;
$row = $wpdb->get_row('SELECT now() as now');

// insert the date into the db
 $wpdb->insert( 
    'wp_date', 
    array(
        'name' => $name,
        'date' => $row->now    
    ), 
    array( 
        '%s',
        '%s'
    ) 
)

所以就像是..。

代码语言:javascript
复制
$mysql_time = $row->now;
$php_time = date('Y-m-d G:i:s');
$blog_time = current_time('mysql');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24849977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档