Update post meta date always store 1970-01-07

I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but wit

I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but with this code always store 1970-01-07 as date.

$lejar_datum = get_post_meta($job_id , '_job_expires', true);
$date = date('Y-m-d',strtotime('+1 week',$lejar_datum));
update_post_meta( $job_id, '_job_expires', $date);

How can I store the current "job_expires" date + 1 week?

I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but with this code always store 1970-01-07 as date.

$lejar_datum = get_post_meta($job_id , '_job_expires', true);
$date = date('Y-m-d',strtotime('+1 week',$lejar_datum));
update_post_meta( $job_id, '_job_expires', $date);

How can I store the current "job_expires" date + 1 week?

Share Improve this question asked Jun 15, 2019 at 10:41 gezukagezuka 175 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

With debugging enabled, you should have gotten the following message:

Notice: A non well formed numeric value encountered

This is because strtotime() expects an integer as its second argument. You could use it like so

$date = date('Y-m-d', strtotime('+1 week', strtotime($lejar_datum)));

or if you want to use the more modern approach with DateTime

$dt = DateTime::createFromFormat('Y-m-d', $lejar_datum)->modify('+1 week');
update_post_meta($job_id, '_job_expires', $dt->format('Y-m-d'));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399489a4626033.html

相关推荐

  • Update post meta date always store 1970-01-07

    I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but wit

    8小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信