1

I have a view constructed with many fields, one of those fields is a date field. I added a filter on my date field that is asking for a relative date. OK, this is no problem, but I have a request to gather all results from month to date. For example, I want to get the results from today's date, back to the beginning of the month. I used for this filter, the operator, "is equal to", the relative date, "this month," and I get no results back, even though there is results between now and the beginning of the month. I was thinking I am using the wrong relative date. I looked up the documentation here: http://php.net/manual/en/datetime.formats.relative.php, and "this month" looks like the correct format, but maybe it is not. Can someone point me in the right direction.

1

I figured out the answer to my question. In the filter option, if you filter the relative time format "first day of this month," and assign the operator "is equal to or greater than," the output will be the first day of the month to the current day. Hope this helps anyone that reads my post.

  • I don't think the author has correctly answered his own question. php -r "echo sprintf('%+d', strtotime('first day of this month'));" This will output +1362137143 The code in the views_handler_filter_date::op_simple is: – Aidan Mar 6 '13 at 11:27
0

I don't think the author has correctly answered his own question.

php -r "echo sprintf('%+d', strtotime('first day of this month'));"

This will output +1362137143

The code in the views_handler_filter_date (op_simple method) is:

$value = intval(strtotime($this->value['value'], 0));
if (!empty($this->value['type']) && $this->value['type'] == 'offset') {
  $value = '***CURRENT_TIME***' . sprintf('%+d', $value); // keep sign
}
$this->query->add_where_expression($this->options['group'], "$field $this->operator $value");

So the views query will be, e.g. node.created >= time()+1362137143, which isn't going to give you what you want.

If you want all nodes created this calendar month, use a Date argument with the granularity set to "Month".

Here's an issue suggesting that there should be an option to use absolute dates evaluated by strtotime; http://drupal.org/node/1935036

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.