How can I programmatically set date field Month, Day, Year dropdowns in Paragraphs? I'm setting a basic date field (and several other text fields) programmatically when creating a paragraph. The database is showing that it is getting my date, which is being stored inY-m-d\TH:i:s format. All the other data is being saved as well. No errors.

However, when I edit the node my paragraph is attached to, all the data is there except for the date field. It's not set despite the data being in the database. 

The date field is set to show MDY in dropdowns like so:



I've tried this: $date = new DateTime('2015-06-01 23:45:52', new \DateTimeZone('UTC')); This does get the date saved into the database, however, the dropdowns are not set.

So then I tried converting it to MDY: $date-&gt;format('M-D-Y') but no such luck. This doesn't work at all.

I have also seen that you have to reference the actual stored format using $date-&gt;format(DATETIME_DATETIME_STORAGE_FORMAT) but there doesn't seem to be other parameters for that to get it into the format that I need.

Is there some way I need to individually set the actual dropdown options in code?

Full paragraph code below. Almost all of these examples save data in the DB correctly, the date dropdowns do not reference it though.

use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\datetime_range\DateTimeRangeTrait;    

  $date = new DateTime('2015-06-01 23:45:52', new \DateTimeZone('UTC'));
  //$date = $date-&gt;format('Y-m-d\TH:i:s');
  // if ($date instanceOf DrupalDateTime &amp;&amp; !$date-&gt;hasErrors()) {
  //   $currentDate-&gt;setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
  //   $db_friendly_value = $currentDate-&gt;format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
  // }

  //$date-&gt;setTimezone(new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE));
  //$date = $date-&gt;format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
  // $date-&gt;setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));

      $program_1 = Paragraph::create([
        'type' =&gt; 'programs',
        'field_program_name' =&gt; 'Program Name',
        'field_program_description' =&gt; 'Description',
        'field_program_year' =&gt; [
          'value' =&gt; $date,
        ],
      ]);
      $program_1-&gt;save();


Am I missing something somewhere? I've been hunting for the correct way to do this for a few days and have tried a number of different ways. I could probably get around this by just changing the field to be a text (date/time) date field instead of dropdowns. 

I tried the suggestion here, but this doesn't seem to work either: Adding content to Paragraph Date Field Drupal 8

Any ideas here?
After trying just about every solution for the date I could find, I finally figured this out.

It seems that it doesn't even matter what the DB is wanting to save the date as. Looking in the DB, the date is being stored as Y-m-d without the trailing H:i:s. Most examples are saying that you need the full date in Y-m-d\TH:i:s format.

This particular dropdown widget for the date field wants only Y-m-d and I only found that out after trying to pass it all kinds of different date strings and it gave me an error message back about the format without the trailing H:i:s.

So all of that garbage that I tried to pass it earlier and formatting was way off. All I needed to do was this, and the paragraph saved properly and the form fields are reflecting the proper date now.

'field_program_year' =&gt; date('Y-m-d', strtotime('2011-11-12')),
'field_eligibility_range' =&gt; [
  'value'=&gt; date('Y-m-d', strtotime('2011-11-12')),
  'end_value' =&gt; date('Y-m-d', strtotime('2011-11-12'))
],