Skip to content

Instantly share code, notes, and snippets.

@prashantdsala
Created February 27, 2024 10:05
Show Gist options
  • Save prashantdsala/a0cbb2a9e6e540ed1c18386d45f411ec to your computer and use it in GitHub Desktop.
Save prashantdsala/a0cbb2a9e6e540ed1c18386d45f411ec to your computer and use it in GitHub Desktop.
Drupal: Get timestamp from date field and current time
<?php
use Drupal\Core\Datetime\DrupalDateTime;
// Check if the event's end date is not present
// or has been passed.
$current_time = new DrupalDateTime('now', 'UTC');
if ($entity->get('field_event_end_date')->isEmpty() || ($current_time->getTimestamp() >= $entity->field_event_end_date->date->getTimestamp())) {
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment