diff --git a/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
index 44a3949..b52e28e 100644
--- a/core/lib/Drupal/Core/Datetime/Element/Datetime.php
+++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php
@@ -247,12 +247,17 @@ public static function processDatetime(&$element, FormStateInterface $form_state
         $html5_min->setDate($range[0], 1, 1)->setTime(0, 0, 0);
         $html5_max = clone($date);
         $html5_max->setDate($range[1], 12, 31)->setTime(23, 59, 59);
-
-        $extra_attributes += array(
-          'min' => $html5_min->format($date_format, $format_settings),
-          'max' => $html5_max->format($date_format, $format_settings),
-        );
       }
+      else {
+        $range = static::datetimeRangeYears($element['#date_year_range']);
+        $html5_min = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $range[0] . '-01-01 00:00:00');
+        $html5_max = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $range[1] . '-12-31 23:59:59');
+      }
+
+      $extra_attributes += array(
+        'min' => $html5_min->format($date_format, $format_settings),
+        'max' => $html5_max->format($date_format, $format_settings),
+      );
 
       $element['date'] = array(
         '#type' => 'date',
diff --git a/core/modules/system/src/Tests/Form/DatetimeTest.php b/core/modules/system/src/Tests/Form/DatetimeTest.php
new file mode 100644
index 0000000..1f207d8
--- /dev/null
+++ b/core/modules/system/src/Tests/Form/DatetimeTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\system\Tests\Form;
+
+use Drupal\Component\Serialization\Json;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests the form API datetime element.
+ *
+ * @group Form
+ */
+class DatetimeTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['form_test'];
+
+  protected $profile = 'testing';
+
+  /**
+   * Tests #type 'datetime' field mix/max attributes.
+   */
+  function testFormDatetimeMinMax() {
+    // Test min/max on empty form.
+    $this->drupalGet('form-test/datetime');
+    $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]', '', 'Found input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]');
+
+    // Post values w/in 1900-2050 and check min/max.
+    $edit = [
+      'datetime[date]' => '2016-12-31',
+      'datetime[time]' => '15:16:17',
+    ];
+    $this->drupalPostForm(NULL, $edit, 'Submit');
+    $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]', '2016-12-31', 'Found input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]');
+
+    // Post values outside 1900-2050 and check min/max.
+    $edit = [
+      'datetime[date]' => '1776-07-14',
+      'datetime[time]' => '01:02:03',
+    ];
+
+    $this->drupalPostForm('form-test/datetime', $edit, 'Submit');
+    $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1776-01-01" and @max="2050-12-31"]', '1776-07-14', 'Found input[@type="date" and @min="1776-01-01" and @max="2050-12-31"]');
+
+    $edit = [
+      'datetime[date]' => '2134-07-14',
+      'datetime[time]' => '01:02:03',
+    ];
+
+    $this->drupalPostForm('form-test/datetime', $edit, 'Submit');
+    $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1900-01-01" and @max="2134-12-31"]', '2134-07-14', 'Found input[@type="date" and @min="1900-01-01" and @max="2134-07-14"]');
+  }
+
+}
diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml
index 2250a0b..cd34bf9 100644
--- a/core/modules/system/tests/modules/form_test/form_test.routing.yml
+++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml
@@ -489,3 +489,11 @@ form_test.get_form:
     _form: '\Drupal\form_test\Form\FormTestGetForm'
   requirements:
     _access: 'TRUE'
+
+form_test.datetime:
+  path: '/form-test/datetime'
+  defaults:
+    _form: '\Drupal\form_test\Form\FormTestDatetimeForm'
+    _title: 'Datetime fields'
+  requirements:
+    _access: 'TRUE'
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDatetimeForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDatetimeForm.php
new file mode 100644
index 0000000..cb8db80
--- /dev/null
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDatetimeForm.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\form_test\Form;
+
+use Drupal\Core\Form\FormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Form constructor for testing #type 'email' elements.
+ */
+class FormTestDatetimeForm extends FormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'form_test_datetime';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form['datetime'] = [
+      '#type' => 'datetime',
+      '#default_value' => NULL,
+      '#date_increment' => 1,
+      '#date_timezone' => drupal_get_user_timezone(),
+      '#required' => TRUE,
+      '#date_date_format' => 'Y-m-d',
+      '#date_date_element' => 'date',
+      '#date_date_callbacks' => [],
+      '#date_time_format' => 'H-i-s',
+      '#date_time_element' => 'time',
+      '#date_time_callbacks' => [],
+    ];
+
+    $form['submit'] = [
+      '#type' => 'submit',
+      '#value' => 'Submit',
+    ];
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $form_state->setRebuild();
+  }
+
+}
