0

I want to get the actual time and add one day to it, setter below is datetime column type and it doesn't accept the date function. What should i do?

$password->setExpiretime(date("Y-m-d", time() + 86400));
iLuvLogix
  • 5,920
  • 3
  • 26
  • 43
  • 1
    Possible duplicate of [Adding one day to a date](https://stackoverflow.com/questions/1394791/adding-one-day-to-a-date) – gp_sflover Oct 20 '18 at 12:14

1 Answers1

0

You may use format method on an instance of DateTime class:

$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow->format('Y-m-d'));

Update

According to the comment submitted by the OP, if the return type should be DateTime Object, you may just use:

$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow);
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
  • Thanks for help but problem was other thing. It doesnt accept string, i put it without format method and works fine. One thing it is tommorow but not equal from now. Today's 20 tommorow is 21 but i want 21 15:04:23 , with time. –  Oct 20 '18 at 11:04
  • Ok i did it! new \DateTime(date("Y-m-d H:i:s", time() + 86400)) –  Oct 20 '18 at 11:13
  • 2
    $password = new \DateTime(); $password->modify("+1 day"); I don't like this workaround with date() and calculation. – Dominic Wehrmann Oct 20 '18 at 11:54