When defining a view, is it possible to set a condition on a field value

For eg.

If <DateFieldValue> == <Todays date> display Fresh instead of <DateFieldValue> ?

In sql speak

SELECT If (<DateFieldValue> == <Todays date>) THEN "FRESH" ELSE "STALE" AS STATUS WHERE TYPE="FRUITS"

I'll be happy with any inputs.

Thanking you in advance.

Edited by WorldFallz - added <code> tags.

Comments

netplay’s picture

Tags seems to be hidden

Again

If [purchase date] == [todays date] display Fresh instead of ?

In sql speak

SELECT If ([purchase date] == [todays date]) THEN "FRESH" ELSE "STALE" AS STATUS WHERE TYPE="FRUITS"

MidGe48’s picture

You could use computed field in CCK, perhaps.

See http://drupal.org/project/computed_field

www.ZuNOB.com

joachim’s picture

With both CCK and Views you can use a template file for a particular field. In that you could check the value given and then choose that to display.
Use CCK or Views depending on where you want it to show.

netplay’s picture

Thanks Guys. I'll try it the way you said.

netplay’s picture

I don't think this would work, as the food status "Stale/Fresh" would be calculated at the time the article is saved. I want the status at runtime

Jennifer_M’s picture

Disclaimer: I'm a relative newbie to both Drupal and Views, so I could be completely wrong here... but I've been trying to figure out Views for my own purposes, with a problem not a million miles away from this.

I think you can probably do it by having the conditional part after you call your View, operating on the result which is returned by Views.

like by taking the result of your View and poking into it to fetch out the date, and then using PHP for the conditional bit.

It may be there's a pretty straightforward way of doing that via either theming your View, or it may be getting more into the realms of custom coding - I'm not sure. It might even be something you can do via a Display of your View (see my ignorance here :-) ). But pretty sure there would be some way of doing it.

A page about theming Views which might be relevant.

I'd also like to sing the praises of people over at Views-module-specific support who have been very helpful to me in my questioning so far.