5

I'd like to create a new field adding 10 days in a date (string format) in QGIS; using the Field Calculator. For example, in the field_1 there is 22/02/2021, in field_new it should become 04/03/2021.

Maybe, I should convert date in number, as you can see in Excel.

enter image description here

Any suggestion?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 22, 2021 at 22:12
2
  • 1
    What is type of the date field? String or Date? Commented Feb 22, 2021 at 22:17
  • "field_1" is a string, also "field_new" will be a string Commented Feb 23, 2021 at 7:49

2 Answers 2

8

You can use something like:

format_date(to_date("field_1",'dd/MM/yyyy')+to_interval('10 Days'),'dd/MM/yyyy')

First you need to convert your string to a date (the to_date() function), so you can add a datetime interval. The format_date() is needed, because the result of + to_interval() will return a datetime format. So you convert the result back to a date only and use your previous date-format as string (dd/MM/yyyy instead of yyyy-MM-dd).

answered Feb 22, 2021 at 22:24
0
6

For string-typed target field:

to_string( to_date( "field_1" , 'dd/MM/yyyy' ) + to_interval( '10 days' ) )

enter image description here


For date-typed target field:

to_date( to_date( "field_1" , 'dd/MM/yyyy' ) + to_interval( '10 days' ) )

enter image description here

answered Feb 22, 2021 at 22:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.