Making automatic updated date and time field in QGIS? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Is it possible to add the time of editing to the table of a shapefile?How to create in QGIS shapefile a field that automatically returns the current dateWhat to do to keep Python code permanent in QGIS 2.14.2?Making automatic updated date and time field in QGISHow to set NULL as default value for a date field in QGIS 2.4?Calculate Date field in ArcPyHow to update a DATE field when moving PostGIS geometry in QGIS?QGIS Server when builds the UPDATE query to postgis sets date field ='' instead of =null which raises an error in the DBQGIS date fields widget - unable to select todays date?Using Map Tips and Ruled Expression in QGIS?Time Manager date format without timeDisplaying time in the Date FieldIs it possible to add the time of editing to the table of a shapefile?Making automatic updated date and time field in QGIS
Is a ledger board required if the side of my house is wood?
What was the first language to use conditional keywords?
Can a new player join a group only when a new campaign starts?
Why is the AVR GCC compiler using a full `CALL` even though I have set the `-mshort-calls` flag?
Is it fair for a professor to grade us on the possession of past papers?
SF book about people trapped in a series of worlds they imagine
How does the math work when buying airline miles?
How would a mousetrap for use in space work?
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
Find 108 by using 3,4,6
Disembodied hand growing fangs
Should I use a zero-interest credit card for a large one-time purchase?
Illegal assignment from sObject to Id
Why do we bend a book to keep it straight?
Drawing without replacement: why is the order of draw irrelevant?
Crossing US/Canada Border for less than 24 hours
Is CEO the "profession" with the most psychopaths?
An adverb for when you're not exaggerating
ArcGIS Pro Python arcpy.CreatePersonalGDB_management
How much damage would a cupful of neutron star matter do to the Earth?
How to write this math term? with cases it isn't working
How were pictures turned from film to a big picture in a picture frame before digital scanning?
Why should I vote and accept answers?
Sum letters are not two different
Making automatic updated date and time field in QGIS?
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Is it possible to add the time of editing to the table of a shapefile?How to create in QGIS shapefile a field that automatically returns the current dateWhat to do to keep Python code permanent in QGIS 2.14.2?Making automatic updated date and time field in QGISHow to set NULL as default value for a date field in QGIS 2.4?Calculate Date field in ArcPyHow to update a DATE field when moving PostGIS geometry in QGIS?QGIS Server when builds the UPDATE query to postgis sets date field ='' instead of =null which raises an error in the DBQGIS date fields widget - unable to select todays date?Using Map Tips and Ruled Expression in QGIS?Time Manager date format without timeDisplaying time in the Date FieldIs it possible to add the time of editing to the table of a shapefile?Making automatic updated date and time field in QGIS
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to make a date and time updated field as I edit an attribute field in this format yyyy-mm-dd 00:00:00 (= 2016-05-08 11:04:00) - my local date/time. The data is in a QGIS 2.14 shapefile and Vector lines as screenshot bellow.
When a feature as NULL in the 'name' field, I want to enter a name for the road and the 'mod' field must receive de modified date/time like '2016-05-08 15:16:00'.
I already tried some options and failed.
I need help to start from beginning.
- I create a new field, date/time type, but stays with NULL value after I edited, in the "name" field, or the feature it self.
- I used too, the expression now(), but stays with NULL value after I edited.
Note: the date seen there, 2016-04-14 is the first value created with "Field Calculator".
I am using QGIS 2.14.
qgis field-calculator update date datetime
|
show 4 more comments
I want to make a date and time updated field as I edit an attribute field in this format yyyy-mm-dd 00:00:00 (= 2016-05-08 11:04:00) - my local date/time. The data is in a QGIS 2.14 shapefile and Vector lines as screenshot bellow.
When a feature as NULL in the 'name' field, I want to enter a name for the road and the 'mod' field must receive de modified date/time like '2016-05-08 15:16:00'.
I already tried some options and failed.
I need help to start from beginning.
- I create a new field, date/time type, but stays with NULL value after I edited, in the "name" field, or the feature it self.
- I used too, the expression now(), but stays with NULL value after I edited.
Note: the date seen there, 2016-04-14 is the first value created with "Field Calculator".
I am using QGIS 2.14.
qgis field-calculator update date datetime
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
2
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
1
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10
|
show 4 more comments
I want to make a date and time updated field as I edit an attribute field in this format yyyy-mm-dd 00:00:00 (= 2016-05-08 11:04:00) - my local date/time. The data is in a QGIS 2.14 shapefile and Vector lines as screenshot bellow.
When a feature as NULL in the 'name' field, I want to enter a name for the road and the 'mod' field must receive de modified date/time like '2016-05-08 15:16:00'.
I already tried some options and failed.
I need help to start from beginning.
- I create a new field, date/time type, but stays with NULL value after I edited, in the "name" field, or the feature it self.
- I used too, the expression now(), but stays with NULL value after I edited.
Note: the date seen there, 2016-04-14 is the first value created with "Field Calculator".
I am using QGIS 2.14.
qgis field-calculator update date datetime
I want to make a date and time updated field as I edit an attribute field in this format yyyy-mm-dd 00:00:00 (= 2016-05-08 11:04:00) - my local date/time. The data is in a QGIS 2.14 shapefile and Vector lines as screenshot bellow.
When a feature as NULL in the 'name' field, I want to enter a name for the road and the 'mod' field must receive de modified date/time like '2016-05-08 15:16:00'.
I already tried some options and failed.
I need help to start from beginning.
- I create a new field, date/time type, but stays with NULL value after I edited, in the "name" field, or the feature it self.
- I used too, the expression now(), but stays with NULL value after I edited.
Note: the date seen there, 2016-04-14 is the first value created with "Field Calculator".
I am using QGIS 2.14.
qgis field-calculator update date datetime
qgis field-calculator update date datetime
edited Jul 14 '17 at 7:38
nmtoken
8,12542866
8,12542866
asked May 7 '16 at 10:51
Carlos PiresCarlos Pires
600318
600318
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
2
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
1
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10
|
show 4 more comments
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
2
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
1
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
2
2
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
1
1
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10
|
show 4 more comments
2 Answers
2
active
oldest
votes
You can use the following code which connects the attributeValueChanged
event to a function we can define which inserts the results of the $now
expression. Highlight your layer and copy/paste the following into the Python Console:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fieldNameIndex('mod')
e = QgsExpression( " $now " )
e.prepare( layer.pendingFields() )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate( feat )
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
Select the feature by clicking the row number (shown in the red box in the image) or from the map canvas and edit any attribute for that feature. The attribute in your mod
field should update:
Note: I used a string field instead of date in order to get the time, otherwise the date field only records YYYY-MM-DD.
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
|
show 9 more comments
I stumbled upon this Q&A while I was looking for a way to date/time stamp changes I was making to records using a plugin. I placed a slightly modified version of the code into the plugin to automatically update the date/time into the record(s) I changed:
""" Prepare Change Date/Time Stamp"""
e = QgsExpression( " $now " )
cDate = e.evaluate()
"""" Identify column(s) to change and new value(s) to assign"""
attrs = 10 : newStat, 20 : cDate
""" Make record change and capture date/time of change'''
layer.dataProvider().changeAttributeValues( fid : attrs )
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f192674%2fmaking-automatic-updated-date-and-time-field-in-qgis%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the following code which connects the attributeValueChanged
event to a function we can define which inserts the results of the $now
expression. Highlight your layer and copy/paste the following into the Python Console:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fieldNameIndex('mod')
e = QgsExpression( " $now " )
e.prepare( layer.pendingFields() )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate( feat )
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
Select the feature by clicking the row number (shown in the red box in the image) or from the map canvas and edit any attribute for that feature. The attribute in your mod
field should update:
Note: I used a string field instead of date in order to get the time, otherwise the date field only records YYYY-MM-DD.
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
|
show 9 more comments
You can use the following code which connects the attributeValueChanged
event to a function we can define which inserts the results of the $now
expression. Highlight your layer and copy/paste the following into the Python Console:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fieldNameIndex('mod')
e = QgsExpression( " $now " )
e.prepare( layer.pendingFields() )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate( feat )
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
Select the feature by clicking the row number (shown in the red box in the image) or from the map canvas and edit any attribute for that feature. The attribute in your mod
field should update:
Note: I used a string field instead of date in order to get the time, otherwise the date field only records YYYY-MM-DD.
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
|
show 9 more comments
You can use the following code which connects the attributeValueChanged
event to a function we can define which inserts the results of the $now
expression. Highlight your layer and copy/paste the following into the Python Console:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fieldNameIndex('mod')
e = QgsExpression( " $now " )
e.prepare( layer.pendingFields() )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate( feat )
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
Select the feature by clicking the row number (shown in the red box in the image) or from the map canvas and edit any attribute for that feature. The attribute in your mod
field should update:
Note: I used a string field instead of date in order to get the time, otherwise the date field only records YYYY-MM-DD.
You can use the following code which connects the attributeValueChanged
event to a function we can define which inserts the results of the $now
expression. Highlight your layer and copy/paste the following into the Python Console:
layer = qgis.utils.iface.activeLayer()
def update():
field = layer.fieldNameIndex('mod')
e = QgsExpression( " $now " )
e.prepare( layer.pendingFields() )
for feat in layer.selectedFeatures():
feat[field] = e.evaluate( feat )
layer.updateFeature( feat )
layer.attributeValueChanged.connect(update)
Select the feature by clicking the row number (shown in the red box in the image) or from the map canvas and edit any attribute for that feature. The attribute in your mod
field should update:
Note: I used a string field instead of date in order to get the time, otherwise the date field only records YYYY-MM-DD.
edited May 9 '16 at 14:54
answered May 9 '16 at 12:08
JosephJoseph
59.1k7102207
59.1k7102207
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
|
show 9 more comments
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
@CarlosPires - Most welcome! Hope it helps :)
– Joseph
May 10 '16 at 9:04
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
so I created a new text string(20) field 'mod' (see 1), I pasted your code into the Python console (after ctrl-alt-P), insert the name of the street 'name' (see 2), left the record but the field is still NULL (see 3) as you see in the screen capture. ![ScreenshotTry] (i.stack.imgur.com/lGR2D.png).
– Carlos Pires
May 10 '16 at 21:35
2
2
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
Now it works! As I am not a programmer did not know we had first run the code !! :( Sorry. Note:It works with the select tool. If the attribute field is edited with the info tool (identify feature), it doesn´t work.
– Carlos Pires
May 11 '16 at 14:32
2
2
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
@CarlosPires You can use the AutoFields plugin for this. Watch this video for an example of automatic calculation of date and time. I guess it should also work if you use the identify tool to update your values, could you please check?
– Germán Carrillo
Aug 19 '16 at 16:44
1
1
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
@GermánCarrillo, it seems a good choice. I will try later. Thanks.
– Carlos Pires
Aug 21 '16 at 12:05
|
show 9 more comments
I stumbled upon this Q&A while I was looking for a way to date/time stamp changes I was making to records using a plugin. I placed a slightly modified version of the code into the plugin to automatically update the date/time into the record(s) I changed:
""" Prepare Change Date/Time Stamp"""
e = QgsExpression( " $now " )
cDate = e.evaluate()
"""" Identify column(s) to change and new value(s) to assign"""
attrs = 10 : newStat, 20 : cDate
""" Make record change and capture date/time of change'''
layer.dataProvider().changeAttributeValues( fid : attrs )
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
add a comment |
I stumbled upon this Q&A while I was looking for a way to date/time stamp changes I was making to records using a plugin. I placed a slightly modified version of the code into the plugin to automatically update the date/time into the record(s) I changed:
""" Prepare Change Date/Time Stamp"""
e = QgsExpression( " $now " )
cDate = e.evaluate()
"""" Identify column(s) to change and new value(s) to assign"""
attrs = 10 : newStat, 20 : cDate
""" Make record change and capture date/time of change'''
layer.dataProvider().changeAttributeValues( fid : attrs )
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
add a comment |
I stumbled upon this Q&A while I was looking for a way to date/time stamp changes I was making to records using a plugin. I placed a slightly modified version of the code into the plugin to automatically update the date/time into the record(s) I changed:
""" Prepare Change Date/Time Stamp"""
e = QgsExpression( " $now " )
cDate = e.evaluate()
"""" Identify column(s) to change and new value(s) to assign"""
attrs = 10 : newStat, 20 : cDate
""" Make record change and capture date/time of change'''
layer.dataProvider().changeAttributeValues( fid : attrs )
I stumbled upon this Q&A while I was looking for a way to date/time stamp changes I was making to records using a plugin. I placed a slightly modified version of the code into the plugin to automatically update the date/time into the record(s) I changed:
""" Prepare Change Date/Time Stamp"""
e = QgsExpression( " $now " )
cDate = e.evaluate()
"""" Identify column(s) to change and new value(s) to assign"""
attrs = 10 : newStat, 20 : cDate
""" Make record change and capture date/time of change'''
layer.dataProvider().changeAttributeValues( fid : attrs )
edited Sep 4 '16 at 21:54
PolyGeo♦
54k1782246
54k1782246
answered Sep 4 '16 at 17:34
rLoganrLogan
312
312
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
add a comment |
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
Technically this seems not to be an answer but I think this "answer" may have some value to a future reader as part of the Q&A and so I am leaving it in place. It needs more formatting than converting it to a comment would allow. I'm happy to be overruled if anyone closer to writing QGIS Plug-ins than I am wants to make a case in comments here and then ping me or another moderator.
– PolyGeo♦
Sep 4 '16 at 21:49
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f192674%2fmaking-automatic-updated-date-and-time-field-in-qgis%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please edit your question to specify the data format and the versions of software in use. You should also specify the datatype of the target column (since date fields don't have formats)
– Vince
May 7 '16 at 13:17
Please edit the question to contain the requested information. You should detail what you have tried, and exactly how it failed. This will help allow our volunteers to understand what you are trying to achieve. As it stands, there isn't enough information to more than guess at a solution -- I'm imagining an autopopulate column in DB2 isn't going to meet your needs.
– Vince
May 7 '16 at 16:41
Sounds to me if you would like to store the timestamp of the last edit/update of a feature in an attribute, did I get you right? Something like what ESRI calls 'editor tracking'?
– Jochen Schwarze
May 7 '16 at 17:21
2
so what kind of data provider are you using (shape, postgis, ...) and by the way: is the 3-digit month a typing error or do you need something like 2016-may-08? perhaps catching the ´beforeCommitChanges´ signal of a ´QgsVectorLayer´ or an ´UPDATE´ trigger in postgesql might be successful.
– Jochen Schwarze
May 8 '16 at 9:19
1
Shapefile is a miserable data format for timestamps, since dBase only supports day resolution (it doesn't really support NULLs either). You need to use a character column for this information (which would then need to be parsed for any further use)
– Vince
May 8 '16 at 15:10