d4ny3l
d4ny3l

Reputation: 163

Typo3 DateTime setter issue

my appointment model has a value $created which is of the datatype DateTime. But for some reason i am not able to set the $created values.

I tried many formats, but it just won't set the value. It gets stuck when the function reaches the setCreated(). (All other values (ints, strings) are set successfully, just this \DateTime var not)

$appointment->setCreated('1439878630');  //Doesn't work
$appointment->setCreated(1439878630);    //Doesn't work  
$appointment->setCreated('1990-11-14T15:32:12+00:00'); //Doesn't work
$appointment->setCreated('1990-11-14 15:32:12'); //Doesn't work

my setter method:

 /**
 * Sets the created
 *
 * @param \DateTime $created
 * @return void
 */

public function setCreated(\DateTime $created) {
    $this->created = $created;
}

how can i set the $created value with a timestamp (or any other date-format)?? any help is appreciated! tia for your efforts.

Upvotes: 2

Views: 529

Answers (3)

Jost
Jost

Reputation: 5850

The setCreated-method needs a DateTime object, not a string. So give it one:

$appointment->setCreated(new \DateTime('<insert your date string here>'));

The list of accepted time strings can be found in the PHP documentation.

Upvotes: 4

Serhat Akay
Serhat Akay

Reputation: 534

Can you try this? It should be working...

$appointment->setCreated(new \DateTime('1990-11-14T15:32:12+00:00'));

Upvotes: 2

Miguel Mesquita Alfaiate
Miguel Mesquita Alfaiate

Reputation: 2968

Have you tried:

$appointment->setCreated('1990-11-14 15:32:12');

Upvotes: 0

Related Questions