diff --git a/serial.inc b/serial.inc
index 28e12a3..99656b4 100644
--- a/serial.inc
+++ b/serial.inc
@@ -144,10 +144,109 @@ function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
   // Get the name of the relevant table.
   $table = _serial_get_table_name($bundle, $field_name);
 
-  // Insert a temporary record to get a new unique serial value.
   $uniqid = uniqid('', TRUE);
+  $fields = array('uniqid' => $uniqid);
+
+  $field_info = field_info_field($field_name);
+  $field_settings = $field_info['settings'];
+
+  if ( $field_settings['year_prefix'] ) {
+    $last_record = db_select($table, 'a')
+      ->fields('a', array('sid'))
+      ->range(0,1)
+      ->orderBy('sid', 'DESC')
+      ->execute()
+      ->fetchAssoc();
+
+    $year_new = date("Y");
+
+    if($last_record == null) {
+      watchdog('serial', t("Initializing serial field: %field_name with year: %year."),
+          array('field_name' => $field_name, '%year' => $year_new));
+      $fields['sid'] = $year_new.'000001';
+    } else {
+      $year_old = substr($last_record["sid"],0,-6);
+
+      if(!$year_old) {
+        if( $field_settings['year_reset'] ) {
+          watchdog('serial', t("Converting serial field: %field_name to year prefixed: %year and resetting the counter."),
+              array('%field_name' => $field_name, '%year' => $year_new));
+          $fields['sid'] = $year_new.'000001';
+        } else {
+          $current_counter = $last_record["sid"];
+          $current_counter++;
+          watchdog('serial', t("Converting serial field: %field_name to year prefixed: %year and keeping the counter: %counter."),
+              array('%field_name' => $field_name, '%year' => $year_new, '%counter' => $current_counter));
+          $fields['sid'] = sprintf("%d%06d", $year_new, $current_counter);
+        }
+      } else {
+        if($year_old != $year_new) {
+          if( $field_settings['year_reset'] ) {
+            watchdog('serial', t("Resetting serial field: %field_name counter because year has changed from: %year_old to %year_new."),
+                array('%field_name' => $field_name, '%year_old' => $year_old, '%year_new' => $year_new));
+            $fields['sid'] = $year_new.'000001';
+          } else {
+            $current_counter = $last_record["sid"] - ( $year_old * 1000000);
+            $current_counter++;
+            watchdog('serial', t("Changing serial field: %field_name to year: %year and keeping the counter: %counter."),
+                array('%field_name' => $field_name, '%year' => $year_new, '%counter' => $current_counter));
+            $fields['sid'] = sprintf("%d%06d", $year_new, $current_counter);
+          }
+        }
+      }
+    }
+  }
+  // Adding new code to add DATE prefix instead of YEAR prefix
+  elseif ( $field_settings['date_prefix'] ) {
+    $last_record = db_select($table, 'a')
+      ->fields('a', array('sid'))
+      ->range(0,1)
+      ->orderBy('sid', 'DESC')
+      ->execute()
+      ->fetchAssoc();
+
+    $date_new = date("Ymd");
+
+    if($last_record == null) {
+      watchdog('serial', t("Initializing serial field: %field_name with date: %date."),
+          array('field_name' => $field_name, '%date' => $date_new));
+      $fields['sid'] = $date_new.'000001';
+    } else {
+      $date_old = substr($last_record["sid"],0,-6);
+
+      if(!$date_old) {
+        if( $field_settings['date_reset'] ) {
+          watchdog('serial', t("Converting serial field: %field_name to date prefixed: %date and resetting the counter."),
+              array('%field_name' => $field_name, '%date' => $date_new));
+          $fields['sid'] = $date_new.'000001';
+        } else {
+          $current_counter = $last_record["sid"];
+          $current_counter++;
+          watchdog('serial', t("Converting serial field: %field_name to date prefixed: %date and keeping the counter: %counter."),
+              array('%field_name' => $field_name, '%date' => $date_new, '%counter' => $current_counter));
+          $fields['sid'] = sprintf("%d%06d", $date_new, $current_counter);
+        }
+      } else {
+        if($date_old != $date_new) {
+          if( $field_settings['date_reset'] ) {
+            watchdog('serial', t("Resetting serial field: %field_name counter because date has changed from: %date_old to %date_new."),
+                array('%field_name' => $field_name, '%date_old' => $date_old, '%date_new' => $date_new));
+            $fields['sid'] = $date_new.'000001';
+          } else {
+            $current_counter = $last_record["sid"] - ( $date_old * 1000000);
+            $current_counter++;
+            watchdog('serial', t("Changing serial field: %field_name to date: %date and keeping the counter: %counter."),
+                array('%field_name' => $field_name, '%date' => $date_new, '%counter' => $current_counter));
+            $fields['sid'] = sprintf("%d%06d", $date_new, $current_counter);
+          }
+        }
+      }
+    }
+  }
+
+  // Insert a temporary record to get a new unique serial value.
   $sid = db_insert($table)
-    ->fields(array('uniqid' => $uniqid))
+    ->fields($fields)
     ->execute();
 
   // If there's a reason why it's come back undefined, reset it.
diff --git a/serial.module b/serial.module
index ef458e0..5a9060f 100644
--- a/serial.module
+++ b/serial.module
@@ -58,17 +58,17 @@ function serial_field_delete_instance($instance) {
 }
 
 /**
- * Implements hook_form_alter().
- */
-function serial_form_alter(&$form, $form_state, $form_id) {
-  if ('field_ui_field_settings_form' == $form_id && 'serial' == $form['field']['type']['#value']) {
-    drupal_set_message(t('Serial field %field has been created.', array(
-      '%field' => $form['field']['field_name']['#value'],
-    )));
-
-    drupal_goto("admin/structure/types/manage/{$form['#bundle']}/fields");
-  }
-}
+ // * Implements hook_form_alter().
+ // */
+// function serial_form_alter(&$form, $form_state, $form_id) {
+  // if ('field_ui_field_settings_form' == $form_id && 'serial' == $form['field']['type']['#value']) {
+    // drupal_set_message(t('Serial field %field has been created.', array(
+      // '%field' => $form['field']['field_name']['#value'],
+    // )));
+//
+    // drupal_goto("admin/structure/types/manage/{$form['#bundle']}/fields");
+  // }
+// }
 
 /**
  * Implements hook_field_presave().
@@ -183,3 +183,62 @@ function serial_field_widget(&$form, &$form_state, $field, $instance, $items, $d
     ),
   );
 }
+
+/**
+ * Implements hook_field_settings_form().
+ */
+function serial_field_settings_form($field, $instance, $has_data)
+{
+  $settings = $field['settings'];
+
+  $form['year_prefix'] = array(
+    '#title' => t('Prefix with current year'),
+    '#type' => 'checkbox',
+    '#default_value' => isset($settings['year_prefix']) ? $settings['year_prefix'] : FALSE,
+    '#required' => FALSE,
+    '#description' => t("Prefix generated serial number with current year (Format: YYYYXXXXXX)<br>\n<span style='color: #FF0000;'>** Please notice that you can't revert this option, once selected it will be always selected.</span>"),
+  );
+  if ( isset($settings['year_prefix']) && $settings['year_prefix'] )
+  {
+    $form['year_prefix']['#disabled'] = TRUE;
+  }
+  $form['year_reset'] = array(
+    '#title' => t('Reset counter on year change'),
+    '#type' => 'checkbox',
+    '#default_value' => isset($settings['year_reset']) ? $settings['year_reset'] : FALSE,
+    '#required' => FALSE,
+    '#description' => t('Reset counter on year change, so on the beginning of a new year the serial starts on 1 again (Format: YYYY000001).'),
+    '#states' => array(
+      'invisible' => array(
+        ':input[name="field[settings][year_prefix]"]' => array('checked' => FALSE),
+        ),
+      ),
+  );
+
+  $form['date_prefix'] = array(
+    '#title' => t('Prefix with current date'),
+    '#type' => 'checkbox',
+    '#default_value' => isset($settings['date_prefix']) ? $settings['date_prefix'] : FALSE,
+    '#required' => FALSE,
+    '#description' => t("Prefix generated serial number with current date (Format: YYYYMMDDXXXXXX)<br>\n<span style='color: #FF0000;'>** Please notice that you can't revert this option, once selected it will be always selected.</span>"),
+  );
+  if ( isset($settings['date_prefix']) && $settings['date_prefix'] )
+  {
+    $form['date_prefix']['#disabled'] = TRUE;
+  }
+  $form['date_reset'] = array(
+    '#title' => t('Reset counter on date change'),
+    '#type' => 'checkbox',
+    '#default_value' => isset($settings['date_reset']) ? $settings['date_reset'] : FALSE,
+    '#required' => FALSE,
+    '#description' => t('Reset counter on date change, so on the beginning of a new date the serial starts on 1 again (Format: YYYYMMDD000001).'),
+    '#states' => array(
+      'invisible' => array(
+        ':input[name="field[settings][date_prefix]"]' => array('checked' => FALSE),
+        ),
+      ),
+  );
+
+
+  return $form;
+}
