QGIS 3.4 calculate date, add month
What a shame the to_interval
expression treats each month as 30 days!
Here's an ugly expression which will do what you want:
to_date(concat(year("date")+floor((month("date")+"months"-1)/12), '-',
right('0' || ((month("date")+"months"-1)%12+1) , 2),'-',
right('0' || day("date"),2)))
It breaks the date down into year, month and day, then uses the "months" field to add the relevant amount of years and months, then concatenates the values to make a string to convert to a date. The to_date
expression is very particular about the input format - the month and day must be two digits - so the right
expressions are used to pad out single digit months/days with a leading zero.
Edit: Now working for when the new month is 12. But this is still a naive solution which will fail when the start date is the 31st of the month and the new month has only 30 days or less.