How to use daterange field programmatically? I activated the Datetime Range core module and it works inside a content type, from the BO, but I want to use it in a custom form. I tried :

  $form['training_interval'] = [
    '#type' =&gt; 'daterange',
    '#required' =&gt; TRUE,
    // '#default_value' =&gt; 'TODO',
  ];


and also daterange_default, datetime_range and any value which could have been relevant giving the module code, but nothing is displayed. I must confess I feel silly...
If you programatically need to set a datetime range field when creating a node in a custom form submit handler for example, you need to to fill two values:
The start date value and the end date end_value.
$node = \Drupal\node\Entity\Node::create([
  'type' =&gt; $type,
  'title' =&gt; $title,
  'field_dates' =&gt; [
    'value'=&gt; '2018-02-02T12:12:12',
    'end_value' =&gt; '2018-05-05T12:12:12'
  ],
]);
$node-&gt;save();