I want to highlight a tablerow when a datefield is less then 6 months from now.
I tried
if ($node_data_field_maturity_field_maturity_value < "now +6 months") return 'red';
but that leaves al rows uncolored, using the ">" instead colors all rows red.
The "now +6 months" does work when used in a views filter.
Does the module support these kind of selections?
Comments
Comment #1
smokrisYou've almost got it.
Right now your code is comparing two strings --- an ISO representation of the datefield value, and the literal string "now +6 months". To PHP this is by default just an undifferentiated string.
You can use the PHP
strtotime()function to convert both the datefield value and the "now +6 months" relative date specifier into numeric time representations, which PHP can then sensibly compare.Try this:
Comment #2
Argus commentedThis works fine indeed (thanks!), but unfortunatly only in the Live Preview. Once I save the view it returns all rows red.
This may be another issue though for I also noticed the same happening on another occasion. FYI I have the module working fine in yet another view.
Comment #3
smokrisClosing inactive support request.
Comment #4
lunk rat commentedI used this same snippet and I also have the problem that it works great only in live preview, and only on the "Defaults" preview. When I preview the "Page", highlighting does not appear. There is no highlighting at all on the actual view, once the view is saved.
I also have highlighting working in a dozen other views on the same site. But with this particular date highlighting, I can only get it to work in the Defaults live preview in views UI.
Comment #5
smokrisHmm. I just created a test site, added a "Date" field to a content type, added a couple sample nodes, and created a view using the above snippet. Highlighting works for me both in preview and on the actual View page.
@LunkRat: please export your Content Type and your View (using Features), and attach the module to this issue, so I can try to recreate your exact scenario. (Or provide a set of instructions for reproducing this issue from a clean test site.)