4

I have a shapefile of crime reports that includes the time a call was received and the time officers arrived on scene. I want to create response times from the difference in these two values. I know QGIS has support for the difference between dates, but I need the difference between two times in hh:mm format. Is there a way to do this in QGIS specifically? I am running QGIS 2.0 standalone version.

  • Are the two times stored in string/text fields just like "hh:mm"? I'm curious about the field type because it really determines how the field calculator needs to be used. – SaultDon Jan 10 '14 at 22:40
  • They are currently string fields. – cbunn Jan 11 '14 at 16:58
  • You can check out a sample of the dataset at github.com/chadbunn/SLO-Crime/blob/master/timestamp – cbunn Jan 13 '14 at 20:39
4

You can try the hour() field calculator function with a nested age() function:

hour(age("FIELD1","FIELD2"))

That should output the difference in hours. But you might have to re-create your input field as Date type and format them like YYYY-MM-DDTHH:MM:SS if not already.

I'm not sure if you can use more nested Conversion functions like tointerval() or hour()/minute()/second() in the above expression if field calculator in QGIS doesn't recognize the fields you input because they might be strings.

hour() and age() function for qgis field calculator

  • I am going to give this a shot since I have a year and date field. – cbunn Jan 11 '14 at 16:59
  • OK I am having trouble creating new date fields that combine the date with the time_recei, and another with the date and time_arriv. I am unfamiliar with how to create a date type column in QGIS but I see that it is possible. I have put a sample of the dataset at github.com/chadbunn/SLO-Crime/blob/master/timestamp in case you want to check it out. Any help or ideas would be very helpful! – cbunn Jan 13 '14 at 20:37
  • @cbunn Sure, having a peek. – SaultDon Jan 13 '14 at 20:49
  • If you want the shapefile I can email it to you. – cbunn Jan 13 '14 at 20:59
  • @SaulDon I had a thought that I could convert my hh:mm fields to the minute equivalent (i.e. hh*60+mm) to get a total minute count and then derive response times in minutes. Is there a good way to create this formula? – cbunn Jan 22 '14 at 22:00
0

I was not able to do this in QGIS, but I was able to do it simply with Excel and edit my .csv file with a new response time category. I'm sure there is a way to do it in QGIS but I could not figure it out.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.