Skip to content

Instantly share code, notes, and snippets.

@sanguis
Created December 11, 2012 15:57
Show Gist options
  • Save sanguis/4259600 to your computer and use it in GitHub Desktop.
Save sanguis/4259600 to your computer and use it in GitHub Desktop.
views_query_alter() snippet date range
if (!empty($fields['min']['date']) || !empty($fields['max']['date'])) {
//date logic
if(!empty($fields['min']['date'])){
$min = new DateTime();
$mindate = explode("/", $fields['min']['date']);
$min->setDate($mindate[0],$mindate[1],$mindate[2]);
$min->setTime(00, 00, 00);
}
else {
$min = new DateTime('19900101');
}
if(!empty($fields['max']['date'])){
$max = new DateTime();
$maxdate = explode("/", $fields['max']['date']);
$max->setDate($maxdate[0],$maxdate[1],$maxdate[2]);
$max->setTime(23, 59, 59);
}
else {
$max = new DateTime('20300101');
}
$query->where[1]['conditions'][3]['field'] = 'node.created BETWEEN ' . $min->format('U') . ' AND ' . $max->format('U');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment