0

I'm trying show some text when it falls between a certain date, but I am having trouble referencing the start date and end date of the date field.

My code is:

$now = time();
$date1 = strtotime($date1);
$date2 = strtotime($date2);
  if ( $now >= $date1 && $now <= $date2) {
  echo 'This is a new video';

     } else {
  echo 'This is an OLD video';
     }

But it is not working because I do not think I am getting the value of the date in $date1 & $date2. My drupal field (named field_time) is set up as a Date (UNIX timestamp). I used the Devel Module to see where the start and end dates are held and it told me "date1" and "date2".

But my code above isn't referencing the field, so im suspicious. Am I referencing the correct date strings above?

  • Where are you using that code? If the field is field_time, and it's a node field, you should at least use $node->field_time. – kiamlaluno Dec 18 '12 at 0:08
0

If that is a node field, then the values you are trying to use are accessible using the following code.

$items = field_get_items('node', $node, 'field_time');

$from = $items[0]['value'];
$to = $items[0]['value2'];

Your Answer

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

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