0

I have a content type having date field contains historical date like 1897-06-15. Now i need to fetch it by week if historical date's week matches current week in Views? How to do it in views.Any suggestions?

  • Just imagine how would you do that in plain SQL, and recreate the same in Views. But I doubt if MySQL supports ISO week numbers :( – Mołot Jul 1 '15 at 5:59
0

I used DAYOFYEAR function.

$startDateNumber = date('z', strtotime("-4 days"));
$endDateNumber = date('z', strtotime("+3 days"));

$query = db_select('field_data_field_historical_date', 'fd');
$query->fields('fd');
$query->where('DAYOFYEAR(fd.field_historical_date_value)>=:startDate', array(':startDate' => $startDateNumber));

$or = db_or();
$or->where('DAYOFYEAR(fd.field_historical_date_value)<=:endDate', array(':endDate' => $endDateNumber));

$nid = $query->condition($or)->execute()->fetchField(3);

if (!is_bool($nid)) {
    print_r($nid); exit;
} else {
    print 'no';
}

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.