[Qgis-user] time in Attribute

Stefan Giese (WhereGroup) stefan.giese at wheregroup.com
Thu Oct 3 02:35:37 PDT 2019


the problem is the missing leading zero in your time format, it should 
be:  '07:13:45' instead of  '7:13:45'
you can use a small function to fill the time string with leading zeros:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def fill_time(timestring, feature, parent):
     list = timestring.split(':')
     newtime = 
str(list[0]).zfill(2)+':'+str(list[1]).zfill(2)+':'+str(list[2]).zfill(2)
     return newtime

and then you can use it in the expression like this:
to_time(fill_time('7:13:45'))

---
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
***************************
Where2B Konferenz 2019
12. Dezember 2019 in Bonn
where2b-conference.com
***************************
WhereGroup GmbH
Schwimmbadstr. 2
79100 Freiburg
Germany

Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11

stefan.giese at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885

Am 2019-10-03 00:42, schrieb RMG:
> Hello,
> 
> I am trying to figure out the duration between one day's survey begin
> time (e.g., 7:13:45) and end time (e.g., 9:39:53) in an attribute
> table of a line shape file. It has just two attributes begin and end.
> But $lengh returns an error message and cannot figure out the
> duration. I suspect that the fields are not in proper format. So, I
> try to update the fields with
> 
> to_time("begin")
> 
> Then, it says Eval Error: Cannot convert '7:13:45' to Time.
> 
> What is a remedy? The “begin” and “end” are in string.
> 
> Best wishes,
> 
> Reiko Matsuda Goodwin
> Comoé Monkey Project [1]
> 
> Guenon Conservation Community [2]
> 
> 
> 
> Links:
> ------
> [1] https://www.facebook.com/ComoeMonkeyProject/
> [2] http://facebook.com/GuenonConservationCommunity/
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the Qgis-user mailing list