I am creating a custom form with "date_popup" form fields.
The only issue I have is that the default_value for the date popup form field shows only the first digit of the year, not the whole date.
Can anyone help with this?
Clive was absolutely right: The default value MUST be set using the date format "Y-m-d", such as with date('Y-m-d', $date)
.
The difference is that I used "Y-M-d" instead of "Y-m-d" for #default_value.
For Drupal 8:
use Drupal\Core\Datetime\DrupalDateTime;
$form['mydatefield']['widget'][0]['value']['#default_value'] = DrupalDateTime::createFromTimestamp(strtotime($mydatestring));
#default_value
in a very specific format to get it to work...'#default_value' => date('Y-m-d', $date)