Hi again, a typo to fix and a note I forgot to add:
- a Date field named "due_date"
the above was of course "duedate", as the mentioned code states:
$due_date_timestamp = strtotime($node->field_duedate[0]['value']);
As for the note, you can see that the timestamp is created parsing a string. This means that you are not obliged to use a Date field - a plain text field will be fine - but using the Date module will ensure the date validation in first place.
My code might not work if the string passed to strtotime is not correctly formatted. Be sure to feed it a correct time format.
Have a nice day, Francesco
2009/5/21 Francesco entuland@gmail.com:
Hi Mohan,
I'm trying to display/hide a cck field based on the input given in another field. My situation is i need to show a cck text field based on the server time...if it doesn't matches, I need to display another cck text field.
here is what I've done: I created a content type with the following:
- a Date field named "due_date"
- a Text field named "answer"
- a Computed field named "computed"
Then I've given this code to the "computed" field:
$answer = $node->field_answer[0]['value']; $t = getdate(); $today_timestamp = $t[0]; $due_date_timestamp = strtotime($node->field_duedate[0]['value']);
if ($today_timestamp >= $due_date_timestamp){ $node_field[0]['value'] = $answer; }else{ $node_field[0]['value'] = "The answer will be shown on " . date('D, m/d/Y - H:s',$due_date_timestamp); }
As you can see from the code, the "if" statement compares the timestamps, then returns the answer or a notice about the due date, depending on the comparison.
Hope this is what you wanted to do - of course you have to hide the "answer" field from display. The code above could be easily adapted to display another field instead of that notice.
I don't know how to do the same work inserting the result into the node's body, I might have a try at it if nobody else has a quick pointer about the solution to your additional request.
Have fun, Francesco