How to calculate timediff (in milliseconds) of two fields in the same event

Thank you very much @Ganesh_Venkataraman. I had written a similar ruby code here. but it fails with a ruby code exception " ```
Ruby exception occurred: allocator undefined for Float


    	date {
    		match => [ "received_at", "dd/mm/yyyy HH:mm:ss.SSS" ]
    		timezone => "UTC"
    		target => "receivedlogtime"
    	  }
    	  
    	date {
    		match => [ "sent_at", "dd/mm/yyyy HH:mm:ss.SSS" ]
    		timezone => "UTC"
    		target => "sentlogtime"
    	  }
    	  
    	  
    	if [received_at] and [sent_at] {
    		ruby {
    			init => "require 'time'"
    			code => "
    				received_by_finacle   = (Time.parse(event.get('received_at')).to_f)*1000;
    				sent_out_by_finacle   = (Time.parse(event.get('sent_at')).to_f)*1000;
    				timetaken = (sent_out_by_finacle - received_by_finacle) rescue nil;
    				event.set('time_delta',timetaken);
    				event.set('epoch_received_at_in_milliseconds',received_by_finacle);
    				event.set('epoch_sent_at_in_milliseconds',sent_out_by_finacle);
    				"
    				add_tag => [ "calculated_time_difference" ]
    		}
    	}    

Thank you very much