Skip to main content
Bumped by Community user
Bumped by Community user
edited title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Any way to filter by Week Number in Views 3week number?

edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Tweeted twitter.com/#!/StackDrupal/status/561245324610899968

Drupal 7, Views 3

I've got several views configured which display data over many years. The data is filtered by Year using a date field as filter criteria. For each year I have attachment views that I need to filter further by week. Rather than determining the exact dates for the weeks of each year and inputting them manually as filter criteria, I'm wondering if there is any way to add a filter criterion to filter by week number, i.e. week 1 thru week 52. That way the only date that needs to be set is the year for each view, and the rest happens automatically according to week number.

I am aggregating a lot of data by year and week in a table view where each column is an additional view attachment and trying to avoid having to manually enter the filters for week dates per year.

Does anyone have any advice/hints for me on this? Thanks very much.

Here is the code I am currently playing with:

function x_week_start($date) {
    $ts = strtotime($date);
    $start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
    return date('Y-m-d', $start);  
}

function x_week_end($date) {
    $ts = strtotime($date);
    $start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
    return date('Y-m-d', strtotime('next saturday', $start));  
}

$date = '2013-01-14';
$start = x_week_start($date);
$end = x_week_end($date);
$inquiry_date = date('Y-m-d', $data->field_field_inquiry_date[0]['raw']['value']);

if ($inquiry_date <= $start) {return FALSE;}

I should add that the field_inquiry_date fieldfield_inquiry_date field is a unix timestamp.

Drupal 7, Views 3

I've got several views configured which display data over many years. The data is filtered by Year using a date field as filter criteria. For each year I have attachment views that I need to filter further by week. Rather than determining the exact dates for the weeks of each year and inputting them manually as filter criteria, I'm wondering if there is any way to add a filter criterion to filter by week number, i.e. week 1 thru week 52. That way the only date that needs to be set is the year for each view, and the rest happens automatically according to week number.

I am aggregating a lot of data by year and week in a table view where each column is an additional view attachment and trying to avoid having to manually enter the filters for week dates per year.

Does anyone have any advice/hints for me on this? Thanks very much.

Here is the code I am currently playing with:

function x_week_start($date) {
$ts = strtotime($date);
$start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
return date('Y-m-d', $start); }

function x_week_end($date) {
$ts = strtotime($date);
$start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
return date('Y-m-d', strtotime('next saturday', $start)); }

$date = '2013-01-14';
$start = x_week_start($date);
$end = x_week_end($date);
$inquiry_date = date('Y-m-d', $data->field_field_inquiry_date[0]['raw']['value']);

if ($inquiry_date <= $start) {return FALSE;}

I should add that the field_inquiry_date field is a unix timestamp.

Drupal 7, Views 3

I've got several views configured which display data over many years. The data is filtered by Year using a date field as filter criteria. For each year I have attachment views that I need to filter further by week. Rather than determining the exact dates for the weeks of each year and inputting them manually as filter criteria, I'm wondering if there is any way to add a filter criterion to filter by week number, i.e. week 1 thru week 52. That way the only date that needs to be set is the year for each view, and the rest happens automatically according to week number.

I am aggregating a lot of data by year and week in a table view where each column is an additional view attachment and trying to avoid having to manually enter the filters for week dates per year.

Does anyone have any advice/hints for me on this? Thanks very much.

Here is the code I am currently playing with:

function x_week_start($date) {
    $ts = strtotime($date);
    $start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
    return date('Y-m-d', $start);  
}

function x_week_end($date) {
    $ts = strtotime($date);
    $start = (date('w', $ts) == 0) ? $ts : strtotime('last sunday', $ts);
    return date('Y-m-d', strtotime('next saturday', $start));  
}

$date = '2013-01-14';
$start = x_week_start($date);
$end = x_week_end($date);
$inquiry_date = date('Y-m-d', $data->field_field_inquiry_date[0]['raw']['value']);

if ($inquiry_date <= $start) {return FALSE;}

I should add that the field_inquiry_date field is a unix timestamp.

added 668 characters in body
Source Link
Loading
Source Link
Loading