4

I'm digitizing a shapefile in QGIS and I need to create a field that returns automatically the current date.

7

I'm assuming you want to automatically populate the field with the date at which the feature was edited - apologies if this is not correct.

Create the shapefile and add a field in the attribute table in which to store the date - you should be able to specify "date" as the type of input.

Add the shapefile into QGIS and then open its properties. Under the "field" option you should see a list of the fields in the shapefile, one of these will be your date field. Click the box marked "text edit" (1 in the image below), from the left hand panel select "date" (2), and ensure that "editable" is selected (3). You can set the date format using the various options.

enter image description here

When you create a feature the date field should be automatically populated, although you can also edit this if need be.

enter image description here

  • Even I see the "time" in the field, after saving come back to NULL value!! – Carlos Pires May 7 '16 at 10:32
  • Sorry Carlos I don't know what might be causing that, but it's likely to be some problem with the compatibility of the field with the data that you're trying to enter it into. Have you tried replicating the issue on a memory layer or a new shapefile? – Ed Rollason May 10 '16 at 9:10
  • Now is working!. I made a new project in QGIS 2.14.2 and a shapfile (lines) with a date/time it displays the date but not time. – Carlos Pires May 11 '16 at 14:17
5

You can create a new field with the field calculator and write the current date with a simple SQL command.

  1. Open the Layer properties
  2. Enable editing
  3. open field calculator
  4. Create a new field using now from the date and time section of the functions

This creates the current date on the new attribute. If you need to write the current date every time you open QGIS you will need another solution The date is not updated everytime but written at the moment of its creation.

  • How can I do that @Papierwolf? I want to see yyy_mmm_dd 00:00:00. I choosed date and used the expression "now()" but only see date yyyy-mm-dd, but is missing time – Carlos Pires May 7 '16 at 10:41
  • There was an open bug on this issue (hub.qgis.org/issues/14190) but it claims to have been fixed. Perhaps try updating to the latest version of QGIS and see whether it works now. – Ed Rollason May 10 '16 at 9:12
  • @EdRollason I made a new project in QGIS 2.14.2 and a shapfile (lines) with a date/time it displays the date but not time. – Carlos Pires May 11 '16 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.