I want to select nodes created before midday today. The use cases are abundant, e.g. order fulfilment cutoffs or competition cutoff times.

I first tried putting "midday" into the relative datetime filter, but that doesn't work as Views does **CURRENT TIME**+strtotime($value).

Now I'm trying an date argument with a PHP default value: return strtotime('1pm'); but that generates this crazy WHERE condition: (( (DATE_FORMAT(ADDTIME(FROM_UNIXTIME(commerce_order.created), SEC_TO_TIME(39600)), '%Y-%m-%d\T%H') >= '2013-03-06T22' AND DATE_FORMAT(ADDTIME(FROM_UNIXTIME(commerce_order.created), SEC_TO_TIME(39600)), '%Y-%m-%d\T%H') <= '2013-03-06T22') ) which only selects orders created during the hour specified.

So it seems the only way to do it is to create a global argument with a PHP code default value which does the following:

$view->query->add_where(0, 'commerce_order.created', strtotime('1pm'), '<=');
return TRUE;

Here's the code to get all nodes/orders created today:

$view->query->add_where(0, 'commerce_order.created', strtotime('yesterday'), '>=');
$view->query->add_where(0, 'commerce_order.created', strtotime('yesterday 23:59:59'), '<=');
return TRUE;

It'd be great if was a third option ("a date calculated by PHPs strtotime"), but otherwise I'm posting this here to help people struggling with this in the future.

Comments

aidanlis’s picture

Issue summary: View changes

Tweaking code sample

mustanggb’s picture

Status: Active » Closed (outdated)