Why doesn't my date get rendered? In Drupal 8, I have a Flag entity with a date field attached.
My code looks like this:
function MYMODULE_flagging_presave(FlaggingInterface $flagging) {
    if ($score == 0 || $score == 1) {
      $flagging-&gt;field_date_review = date(&quot;Y-m-d&quot;, strtotime('today'));
    }
    else {
      $date = date(&quot;Y-m-d&quot;, strtotime(&quot;+$interval days&quot;));
      $flagging-&gt;field_date_review = $date;
    }

I checked and the dates get stored in the database like 2020-07-02.
I have a custom view that shows these flaggings, and I added a filter for nodes with a date field value of less than +1 days; this behaves as expected, so the Views module seems to understand the dates as I stored them.
But, when I try to add the date field, I get an empty display in Views.
Further debugging
When I render the flagging entity, the date field doesn't show a value, either.
Other fields set in ``hook_flagging_presave()` are displayed correctly; it's only the date field that doesn't have a value.
Configuration
On the flagging entity's Manage display screen, I have set my date field to use the Plain format with no timezone offset. I also tried the Default format and several others, but nothing let me display the value.
There are no errors in the recent log messages.
To sum up: the date field has data in the database, which Views can see and use for filters.  But, this date field cannot be displayed in Views or on the rendered flagging entity.
What do I need to do to get the date to be displayed?
I found it-- the Date field can store dates or datetimes, and you have to change your code for each case.
When you add a Date field to an entity, you can choose Date (date) or Date and time (datetime) as the Date type.
More information in this blog post, but the basic idea is:
$node-&gt;set('field_date', date('Y-m-d', time()));
$node-&gt;set('field_datetime', date('Y-m-d\TH:i:s', time()));