0

I have a custom type Clinical Record where some field is cli:date_created. The type of this property is Date.

When I try to set this field (with php) I get Argument of type "string" given but argument of type "\DateTime" was expected.". But I am giving a Date and not a string.

'cli:date_created' => date('d/m/Y',strtotime($resultado[0]['fecha_alta'])),

What do I have to do in order to insert a date? Because I don't want to change the type from date to string in this field.

phoenixSid
  • 447
  • 1
  • 8
  • 22
aivdev
  • 59
  • 7

1 Answers1

1

Yes, you do give a string argument as the date function returns string.

Return Values ΒΆ

Returns a formatted date string. If a non-numeric value is used for timestamp, FALSE is returned and an E_WARNING level error is emitted.

You need to pass a DateTime instance, e.g. using new \DateTime() constructor or another function that return a DateTime instance such as DateTime::createFromFormat

'cli:date_created' => DateTime::createFromFormat('[yourformat]', $resultado[0]['fecha_alta']),
marekful
  • 14,986
  • 6
  • 37
  • 59