Reputation: 393
I have a Entity.
I create a field as Datetime
format
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=true, unique=false)
*/
private $date;
The field in Database is Ok after execute schema update.
This is the mapping to use on Sonata, and show correctly:
->add('date', 'sonata_type_datetime_picker', [
'label' => 'admin.entity.community.fields.date.label',
'required' => true,
'format' => 'dd/MM/Y',
'dp_pick_time' => false,
'dp_use_current' => true,
])
Select 01/07/2018 on the field. Save
In the DB saved the value: 2017-12-25 00:00:00.000000
On preUpdate
i trace the field. The result of the trace:
object(DateTime)#950 (3) { ["date"]=> string(26) "2017-12-25 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Madrid" }
Upvotes: 2
Views: 422
Reputation: 68
just you can edit :
->add('date','sonata_type_date_picker',array('label' => 'Date','widget' => 'single_text','format' => 'yyyy-MM-dd',))
@documentation Sonata-Admin Bundle : https://sonata-project.org/bundles/core/master/doc/reference/form_types.html
Upvotes: 4