0

All,

I have created a Content Type which includes a field of type Date. I would like to create a Views filter such that only those nodes whose date falls within the current month are selected. Can someone please show me how to accomplish this.

Thank you.

I did some more digging and believe that the best approach is to use PHP Views. I installed the module, wrote my 'challenging' code, but am not getting the expected results.

For debugging purposes, I created the following output field code:

<?php
$field_forumdate = $data->_field_data['nid']['entity']->field_forumdate['und']['0']['value'];
$forumdate=strtotime($field_forumdate);
$currdate=time();
$nc = date('n', $currdate);
$nf = date('n', $forumdate);
$tflag = 'false';
if ($nc == $nf) {
  $tflag = 'true';
}
print 'Current month: ' . $nc . ', Forum month: ' . $nf . ', tflag: ' . $tflag;
?>

I created three Content types, and set the ForumDate fields to dates in October, November, and December. Looking at the preview, I see the following:

Current month: 12, Forum month: 12, tflag: true
Current month: 12, Forum month: 11, tflag: false
Current month: 12, Forum month: 10, tflag: false

Next, I created my filter code - which is identical to the above:

$field_forumdate = $data->_field_data['nid']['entity']->field_forumdate['und']['0']['value'];
$forumdate=strtotime($field_forumdate);
$currdate=time();
$nc = date('n', $currdate);
$nf = date('n', $forumdate);
if ($nc != $nf) {
  return TRUE;
}

The problem is that all three nodes are still being returned, i.e., the filter does not seem to be filtering. Please help!

1 Answer 1

0

Hope this will help,Create a view, Add a FILTER CRITERIA on content date field select the following option enter image description here enter image description here

It will return all content which is lies on current month for the respective date field. Good luck

1
  • Brilliant - never thought to try that. Many thanks!
    – GRoston
    Commented Dec 26, 2013 at 5:01

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.