[Qgis-developer] datetime difference between 2 datetimes in Field Calculator

Nyall Dawson nyall.dawson at gmail.com
Tue May 24 00:21:07 PDT 2016


On 23 May 2016 at 21:21, Richard Duivenvoorde <richard at duif.net> wrote:
> Nyall Dawson schreef op 2016-05-23 11:41:
>>>
>>> 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


More information about the Qgis-developer mailing list