现有PHP函数中的strtotime


strtotime within existing PHP function

我有一个现有的PHP函数,可以像这样更新MySQL记录。我需要设置一个日期字段,但在正确格式化PHP时遇到了问题。目前运行良好:

update_post_meta( $post_id, 'adverts_email', 't@t.com');

t@t.com是普通文本。

对于到期日期,我希望使用strtotime('+20天');以unix时间戳格式写出来,如1449203160,翻译成人形为2015年12月4日@4:26。

我试过很多的变体strtotime('+20天');'。或'.strtotime('+20天');.'有和没有;而且它不起作用。我不确定问题是语法还是strtotime在我应该使用DATETIME或其他方法时的使用,还是两个问题的组合?

破裂:

update_post_meta( $post_id, '_expiration_date', 'strtotime('+20 days');');

如前所述,语法高亮显示了问题。以下是应该有效的解决方案:

update_post_meta( $post_id, '_expiration_date', strtotime('+20 days'));

这假设_expiration_date字段是一个整数/unix时间戳,但该字段更有可能是DATETIMETIMESTAMP类型。因此,这可能会更好地发挥作用:

update_post_meta( $post_id, '_expiration_date', date('Y-m-d H:i:s', strtotime('+20 days')));