QGIS Expression – Calculate Date Difference (Days) with Expressions in QGIS

datedatetimeexpressionqgis

I would like to calculate the number of days between two dates. The first date is written in attribute table [YYYY-MM-DD] (creation date) and the second is today [now()]. The goal is, to get the age of every feature.
I need it as QGIS expression to create a virtual field.

date1 (attribute in table) - now() = age (as virt. field)

Best Answer

You can compute the duration between the two dates using the age function. Since it returns a timespan, you can then extract the number of days from it.

day(age(now(),"creation_date"))
Related Question