time in Attribute

classic Classic list List threaded Threaded
2 messages Options
RMG
Reply | Threaded
Open this post in threaded view
|

time in Attribute

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,

_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: time in Attribute

Stefan Giese (WhereGroup)
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

[hidden email]
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
> [hidden email]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user