开发者

Drupal Computed Field - Calculating Time

I am using a popular module called "Computed Field" in Drupal. I have used this field to make on the fly computations for several quote systems. I'm trying to use it to calculate the difference in time for a timesheet type of application. So a user enter in two times into CCK date fields (using PHP custom input g:i - ie 10:20 - year added automatically) but for some reason, I can't get the computed field to show any calculations.

Here is the most simple test example...still wont work

$start_value = $no开发者_运维技巧de->field_ts_train_start[0]['value'];
$end_value = $node->field_ts_train_end[0]['value'];


$node_field[0]['value'] = $end_value - $start_value;

From here, we pass the variable to $display. Can anyone see why this isn't working? I am open to any suggestions on how to work around the computed field, or to build custom functions using integers instead of UNIX time stamps..

Thanks.

Tim


The key to this was to use the date stamp CCK field with custom input field. The date stamp should include all levels of time, with the custom input only collecting HH:MM. This creates a full unix timestamp.

Then use a computed field to subtract start time from end time. This way the stamp is stored as an integer, and the time can be divided by 60 to get the amount of minutes.

$start_value = $node->field_ts_start_train[0]['value'];
$end_value = $node->field_ts_end_train[0]['value'];
$node_field[0]['value'] = $end_value - $start_value;


Use the timestamp key, not value. Value is the string representation (January 1st, 2010), while timestamp is the UNIX time (1234567890)

$start_value = $node->field_ts_train_start[0]['timestamp'];
$end_value = $node->field_ts_train_end[0]['timestamp'];
$node_field[0]['timestamp'] = $end_value - $start_value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜