1

I am adding number stored in custom user meta data to current date. Here is my code

$addeddays = get_user_meta($this->order->user_id, 'xxx', true);
$timeBase = date('j.n.Y');
echo date('j.n.Y', strtotime($timeBase, "+ $addeddays days"));

But output is 1.1.1970

What is wrong in code or how to do it with other method? I read question about this but in answers was also my method so I do not know why it is not working.

closed as off-topic by rudtek, shanebp, Jacob Peattie, Dave Romsey, Rick Hellewell Nov 16 '18 at 18:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • this is actually a php question, not wordpress. You would get more answers by putting in a different forum. – rudtek Nov 12 '18 at 21:12
0

your code is not working, because you use strtotime incorrectly... It should be used like this:

int strtotime ( string $time [, int $now ] )

But you pass formatted dated as first param, and another string as second one.

So how should it look like? Like so:

$addeddays = intval( get_user_meta($this->order->user_id, 'xxx', true) );
$timeBase = date('Y-m-d');
echo date('j.n.Y', strtotime( "+ {$addeddays} days", strtotime( $timeBase ) ));

Or a simpler version (since `$timeBase is today:

$addeddays = intval( get_user_meta($this->order->user_id, 'xxx', true) );
echo date( 'j.n.Y', strtotime( "+ {$addeddays} days" ) );
  • 1
    This is working right. Thanks for answer. It helped me understand these date functions. – mato0 Nov 16 '18 at 10:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.