I'm using Drupal 7 date field. Using views, when the date has expired, the page goes to a section labeled 'past events.' In the template page, the date and time are both separated for instance. $date_output and $time_output. I need to hide the time field after the date has expired. any ideas?

  • You probably need to explain this a little more. Is there any specific reason why you can't compare with the current date and hide the date/time fields?
    – AKS
    Aug 20, 2014 at 17:08
  • thats what I'm looking for apparently. How to do the compare. I've followed a few tuts but not seem to work. Aug 20, 2014 at 17:09
  • Can you show us the template page you are referring in the question?
    – AKS
    Aug 20, 2014 at 18:54

1 Answer 1


If your date is in one of the supported date/time formats, you can use strtotime() and date() to compare. Wrap the printing of $time_output in an if statement. For example:

if ( strtotime($date_output) > date() ) {
  // $date_output is greater than now, eg, not expired

If $date_output is already a timestamp, no need to use strtotime()

  • Ok so this is what I'm working with. The 'time' div should be hidden if the date has past. This is what I have. Trying to see if this works also. I want to show my div based on a date expiration. Here is what I have <?php if (isset($_POST['org']) && $_POST['org'] == "yes") { echo "<div class="time event-info"> <span class="heading">Time</span> <span class="info"><?php print render($time_output); ?></span>"; } else { echo "<div id='layer' style='display: none'>"; } ?> Aug 20, 2014 at 21:21
  • include in your existing if statement, so it shows as: if (isset($_POST['org']) && $_POST['org'] == "yes" && strtotime($date_output) > date()) {
    – faerysteel
    Aug 20, 2014 at 22:22
  • Or do you mean to say that $date_output is not available in the script rendering $time_output? In that case, is this your time field template? The template should have access to the node or entity containing the date field, you may have to check that to get the date output value.
    – faerysteel
    Aug 20, 2014 at 22:42
  • its all relative to the date. if the date has past, then the time shouldnt show. Aug 21, 2014 at 13:16
  • 1
    ok. figured it out. thought i'd share. <?php if (isset($time_output) && $time_output != '' && $date_timestamp > date('U') ):?> <div class="time event-info"> <span class="heading">Time</span> <span class="info"><?php print render($time_output); ?></span> </div> <?php endif; ?> Aug 21, 2014 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.