Discussion:
[Qgis-developer] datetime difference between 2 datetimes in Field Calculator
Richard Duivenvoorde
2016-05-23 09:12:06 UTC
Permalink
I have a start-datetime (string) and a an end-datetime (string) in the
attributes of my vector data.

I can use the to_datetime(str) function in the Field Calculator to
create DateTime objects from these.

But now it would be cool to check the time-difference between those two
(called timespan?).
I did not find a function for those...

Any hints?

If I did not miss something, I think there is not even a Qt function for
this...

A function to add could be: 'to_timemillies', then the user could create
timemillies from the DateTime-objects, and do some calculation on those
him/herself...

Would that be usefull?

Regards,

Richard Duivenvoorde
Nyall Dawson
2016-05-23 09:41:11 UTC
Permalink
Post by Richard Duivenvoorde
I have a start-datetime (string) and a an end-datetime (string) in the
attributes of my vector data.
I can use the to_datetime(str) function in the Field Calculator to create
DateTime objects from these.
But now it would be cool to check the time-difference between those two
(called timespan?).
I did not find a function for those...
Use the age() function. That takes two datetimes and returns an
interval length between them. You can extract the
seconds/minutes/hours/etc from an interval type using the seconds(),
minutes(), ... etc functions.

Hope that helps!
Nyall
Post by Richard Duivenvoorde
Any hints?
If I did not miss something, I think there is not even a Qt function for
this...
A function to add could be: 'to_timemillies', then the user could create
timemillies from the DateTime-objects, and do some calculation on those
him/herself...
Would that be usefull?
Regards,
Richard Duivenvoorde
_______________________________________________
Qgis-developer mailing list
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Nyall Dawson
2016-05-24 07:21:07 UTC
Permalink
Post by Nyall Dawson
Post by Richard Duivenvoorde
But now it would be cool to check the time-difference between those two
(called timespan?).
I did not find a function for those...
Use the age() function. That takes two datetimes and returns an
interval length between them. You can extract the
seconds/minutes/hours/etc from an interval type using the seconds(),
minutes(), ... etc functions.
Hope that helps!
Ah :-) definitely... Did find see that one...
FYI - as of https://github.com/qgis/QGIS/commit/8ddcf76 you can now
just directly calculate date/time/datetime differences using "-", eg

to_date('2016-03-04')-to_date('2016-03-01')

This will return an interval object which you can then use seconds(),
minute(), etc on.

Nyall
Thanks!
Richard
Nathan Woodrow
2016-05-24 07:27:26 UTC
Permalink
Win!
Post by Nyall Dawson
Post by Nyall Dawson
Post by Richard Duivenvoorde
But now it would be cool to check the time-difference between those two
(called timespan?).
I did not find a function for those...
Use the age() function. That takes two datetimes and returns an
interval length between them. You can extract the
seconds/minutes/hours/etc from an interval type using the seconds(),
minutes(), ... etc functions.
Hope that helps!
Ah :-) definitely... Did find see that one...
FYI - as of https://github.com/qgis/QGIS/commit/8ddcf76 you can now
just directly calculate date/time/datetime differences using "-", eg
to_date('2016-03-04')-to_date('2016-03-01')
This will return an interval object which you can then use seconds(),
minute(), etc on.
Nyall
Thanks!
Richard
_______________________________________________
Qgis-developer mailing list
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Richard Duivenvoorde
2016-05-24 08:34:16 UTC
Permalink
Post by Nyall Dawson
FYI - as of https://github.com/qgis/QGIS/commit/8ddcf76 you can now
just directly calculate date/time/datetime differences using "-", eg
to_date('2016-03-04')-to_date('2016-03-01')
This will return an interval object which you can then use seconds(),
minute(), etc on.
kewl! Thanks again :-)

Loading...