I am using Symfony 4 and a Database in which my information is stored. I retrieve them with a Fetch in JavaScript. In my Entity, I have an object of type "dateinterval". In the Database, for an item I have + P00Y00M14DT00H00M00S. When I get that in JavaScript, I have the value P0Y0M14DT0H0M0S. I want to recover the value of the year of the month and days. I tried with substr (5, 2) but when my value of days is null it contains only one digit: P0Y1M0DT0H0M0S and it does not work.
In my Entity
/**
* @ORM\Column(type="dateinterval")
* @Groups({"read"})
*/
private $duration;
In my FormType
->add('duration', DateIntervalType::class, [
'widget' => 'choice',
'with_years' => true,
'with_months' => true,
'with_days' => false,
'with_weeks' => true,
'placeholder' => [
'years' => 'Années',
'months' => 'Mois',
'weeks' => 'Semaines'
],
'labels' => [
'years' => 'Années',
'months' => 'Mois',
'weeks' => 'Semaines'
]
])
In the Database
+P00Y01M00DT00H00M00S
+P00Y00M14DT00H00M00S
+P00Y00M63DT00H00M00S
In my Fetch JavaScript, the values received:
P0Y1M0DT0H0M0S
P0Y0M14DT0H0M0S
P0Y0M63DT0H0M0S