1

I have two date fields. The standard Drupal 7 "Content: Post date" and "Content: Updated date" fields.

I want to calculate the difference in day's between those two date fields and update a third field with the calculated value in the same node when the node is updated.

Here is my Current Rule

(Convert first date field to Unix Time)

Convert data type    
Parameter: Target type: Integer, Value to convert: [node:created]    
Provides variables: Date Created (date_created)    

(Convert second date field to Unix Time)

Convert data type    
Parameter: Target type: Integer, Value to convert: [node:changed]    
Provides variables: Date Changed (date_changed)    

(Subtract the two timestamps from one another to get the number of seconds between each)

Calculate a value       
Parameter: Input value 1: [date-changed], Operator: ( - ), Input value 2: [date-created]    
Provides variables: Calculate Days (calculate_days)

(Divide calculated timestamp by the number of seconds in a day to get the number of days)

Calculate a value    
Parameter: Input value 1: [calculate-days-variable], Operator: ( / ), Input value 2: 86400    
Provides variables: Calculate Days in Seconds (calculate_days_in_seconds)    

(Convert the value to an integer and round to get a whole number (if needed))

Convert data type    
Parameter: Target type: Integer, Value to convert: [calculate-days-in-seconds], Rounding behavior: Always up (9.5 -> 10)    
Provides variables: Conversion result (conversion_result)    

(Add Calculaton to custom field)

Set a data value    
Parameter: Data: [node:field-days], Value: [calculate-days-variable]    

The output from this rule seems to be correct and is giveing me "166349" which is 1 days, 22 hours, 12 minutes and 29 seconds.

What I am trying to do now is figure out how to convert that number "166349" to the number of days which in this case should be 2 days when it is rounded up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.