I have a layer that has date and time information and I need the difference between this information in seconds, I managed to get close to this but I needed to loop for the difference between the features. I used something like:
campotempo = pr.fieldNameIndex('Data/Hora GPS')
tempo1= feature1.attributes()[campotempo]
tempo2 = feature2.attributes()[campotempo]
tempo1form = datetime.datetime.strptime(tempo1, "%d/%m/%Y %H:%M:%S")
tempo2form = datetime.datetime.strptime(tempo2, "%d/%m/%Y %H:%M:%S")
datarange = ((tempo1form - tempo2form).seconds)
with edit(vl):
for f in vl.getFeatures():
f['Tempo(s)'] = datarange
vl.updateFeature(f)
But it did not work
How can I use PyQGIS to make the difference between the time of each feature?