Skip to main content
added 146 characters in body
Source Link
user72672
user72672

As @mrlexington says theThe created date is stored in the node_field_data table as a UNIX timestamp in a cloumn called created.

Here's the code you would use to fetch the nodes that has been created X days ago, using a direct select query.

$day = 86400; // One day in seconds.
 
$days = 3; // The amount of days ago to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

Make sure to inject the database and the entity_type.manager services (if possible) when implementing the code yourself.

As @mrlexington says the created date is stored in the node_field_data table as a UNIX timestamp.

Here's the code you would use to fetch the nodes that has been created X days ago using a direct query.

$day = 86400; // One day in seconds.
 
$days = 3; // The amount of days to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

The created date is stored in the node_field_data table as a UNIX timestamp in a cloumn called created.

Here's the code you would use to fetch the nodes that has been created X days ago, using a direct select query.

$day = 86400; // One day in seconds.
$days = 3; // The amount of days ago to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

Make sure to inject the database and the entity_type.manager services (if possible) when implementing the code yourself.

added 23 characters in body
Source Link
user72672
user72672

As @mrlexington says the created date is stored in the node_field_data table as a UNIX timestamp.

Here's the code you would use to fetch the nodes that has been created X days ago using a direct query.

$day = 86400; // One day in seconds.

$days = 3; // The amount of days to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

As @mrlexington says the created date is stored in the node_field_data table as a UNIX timestamp.

Here's the code you would use to fetch the nodes that has been created X days ago using a direct query.

$day = 86400;

$days = 3; // The amount of days to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);

As @mrlexington says the created date is stored in the node_field_data table as a UNIX timestamp.

Here's the code you would use to fetch the nodes that has been created X days ago using a direct query.

$day = 86400; // One day in seconds.

$days = 3; // The amount of days to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);
Source Link
user72672
user72672

As @mrlexington says the created date is stored in the node_field_data table as a UNIX timestamp.

Here's the code you would use to fetch the nodes that has been created X days ago using a direct query.

$day = 86400;

$days = 3; // The amount of days to fetch from.

$nids = \Drupal::database()->select('node_field_data', 'n')
  ->addField('n', 'nid')
  ->condition('n.created', \Drupal::time()->getCurrentTime() - $days * $day, '>')
  ->execute()
  ->fetchField();

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids);