Pipeline Date range difference in seconds or minutes

In a message having two date fields. One is start_time and other is end time. Need to calculate difference of these two times in minutes or seconds in pipeline processing. Please help to fix this.

rule “Timestamp”
when
true
then
let first_time = flex_parse_date(to_string($message.first_occur_time))); //yyyy-MM-dd HH:mm:ss
let last_time = flex_parse_date(to_string($message.last_occur_time)); //yyyy-MM-dd HH:mm:ss
let ts_start_seconds = seconds(to_long(first_time));
let ts_end_seconds = seconds(to_long(last_time));
set_field(“total_time_taken”, ts_end_seconds-ts_start_seconds);

end

you might want to adopt the rule from the following:

rule "calc_processing_time"
when
  // REQUESTTIME Format hh:mi:ss.mmm
  has_field("REQUESTTIME") AND
  // RESPONSETIME Format hh:mi:ss.mmm
  has_field("RESPONSETIME")
then
    // the math of RESPONSETIME minus REQUESTTIME
    // translated to milliseconds
    set_field( "processing_time", parse_date(
    				value: to_string($message.RESPONSETIME), 
    				pattern: "HH:mm:ss.SSS", 
    				locale:"en" ).millis - parse_date(
    						value: to_string($message.REQUESTTIME),
    						pattern: "HH:mm:ss.SSS", 
    						locale:"en" ).millis );
1 Like

Thanks Jan. It worked for me.