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?
1 Answer
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';
}