3

I have a .shp file with includes a column of format Double that is the Arrival time.

The time values entered are decimal time. For instance, 1 record has a decimal time of 7.11194, which converts to 07:06:43

What is the easiest method to convert this value so I can use it in QGIS?

I've tried using the totime value in QGIS, but no luck.

1
  • What have you tried so far? I'd simply go for "manual" conversion, aka build a field calculator expression and be done with it. Do you have to repeat this process?
    – Erik
    Jun 15, 2020 at 8:46

1 Answer 1

7

Wow this is very fun and... extremely hard for me. Assuming "arrival" as your Arrival time field:

Hour........... lpad(to_string(floor("arrival")),2,0)

Minutes...... lpad(to_string((floor("arrival"*60)%60)),2,0)

Seconds..... lpad(to_string(round(("arrival"*3600)%60)),2,0)

Wrapping the above into single expression, it becomes:

lpad(to_string(floor("arrival")),2,0) || ':' || lpad(to_string((floor("arrival"*60)%60)),2,0) || ':' || lpad(to_string(round(("arrival"*3600)%60)),2,0) 

Hope you'll get better answers.

enter image description here

2
  • Sorry for the delay, this is the first time i've had the chance to try your suggestion, but it has worked I'm not a programmer by any stretch of the imagination; I can do some basic stuff in MapInfo and QGIS, but this had me stumped once trying the totime syntax in qgis failed Thank-you for your assistance regards
    – Simon Hume
    Jun 20, 2020 at 14:24
  • You can omit to_string() here, as lpad() automatically transforms the field value into a string.
    – winnewoerp
    May 16, 2023 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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