When using Views, if you add a Node: Created filter to the Filter Criteria, you get two options for Value type:

  • A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.
  • An offset from the current time such as "+1 day" or "-2 hours -30 minutes"

These are the same options you get when filtering a Date field, but in the database, the node creation date is stored as a timestamp, not a date.

I added a custom field of type Timestamp to my node using Field UI. However, when I added my custom field to Views as a filter, I don't get the date options; instead, I get the standard options of operator "is equal to", "is less than", "is greater than", etc.

I don't understand why core timestamp fields are treated differently than timestamp fields created with Field UI.

In the Views code, in web/core/modules/views/src/EntityViewsData.php, I found this:

// Set up the field, sort, argument, and filters, based on
// the column and/or field data type.
// @todo Allow field types to customize this.
// @see https://www.drupal.org/node/2337515
switch ($field_type) {
  // Special case a few field types.
  case 'timestamp':
  case 'created':
  case 'changed':
    $views_field['field']['id'] = 'field';
    $views_field['argument']['id'] = 'date';
    $views_field['filter']['id'] = 'date';
    $views_field['sort']['id'] = 'date';

The linked issue states:

Views integration works for config fields created in the UI, but not for base fields added to the entity types in code.

My field was created using the UI, but it's still not working...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.