Hot answers tagged

19

I'm surprised I haven't seen this before. Maybe I'm overlooking something obvious :) Although you're using a different locale to me, you're using the same date format as I do in the UK, dd/MM/yyyy. I get a slightly different error (on QGIS 2.16.1) but it doesn't like that date format. You can get around this by creating a short python script in the ...


15

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 &...


13

I have not used the Time Manager plugin either, but I think @Pedro is correct, this is a task for a field calculator first. Once you create the new field and fill it, then use the Time Manager to act upon the new data. In this case, Python might make this an easier operation, given that it has some pretty powerful string operators. The default field ...


11

An update Cursor will out perform the field calculator 100% of the time. You need to write this as an expression: import arcpy, datetime fc = r'C:\GIS\CARGIS\SHAPES.gdb\CRASH_ON_2013' field = "DTCARXTRCT" exp = '''def add_date(): import time return time.strftime("%Y/%m/%d")''' arcpy.CalculateField_management(fc, field, 'add_date()', ...


9

Just tried it out, for me (QGis 2.18) format_date(now(),'dd.MM.yyyy') works. /edit: You need to put the [% %] around your whole expression, then it should work, like: [%'Datum: ' || format_date(now(),'dd.MM.yyyy')%] Note the pipes (||) between the parts of the expression, they are necessary. /edit2: now() gives you the full date, incl. time, which is a ...


8

File geodatabase dates are actually numbers in the underlying database, with days being the basis for whole numbers. Therefore the expression would simply be for event date field values that are greater than or equal to the current date minus 2 days or for event date field values that are greater than the current date minus 3 days. DATE >= CURRENT_DATE - 2 ...


8

I was able to filter using "START_DATE" > '2001-01-01' (double quote for Fields and single quote for Variable are important) if I opened the attribute table and used select by expression, but the same expression failed using query builder using QGIS 2.8.


8

You need to convert your date into datetime object for max() to work correctly. It appears field calculator doesn't see the value as a datetime object. You may need to adjust the date format to suit your region date settings. See Strptime Behavior in the Python docs. Using the Python Parser, select Show Codeblock. In the Pre-logic script code: from ...


8

Apart from the Esri Editor Tracking extension there is no way to determine the 'age' of a polygon in a feature class; note that merge or append operations done outside an edit session will not get entries in the tracking table. In a geodatabase you could have a reasonable guess based on the OID or OBJECTID field (not FID, that's different) as these IDs are ...


7

This is Even Rouault's answer to the OGR ticket: "The issue is that binary comparisons of date/datetime field have never (yet) been implemented in OGR SQL dialect. In 1.10 and before, in fact, it turned to be an implicit conversion to string, which can cause really strange behaviour. For example, you could have well used "select * from test2 where 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 ...


7

As @Kersten commented, you should use a client side loop var size = S2VI.size().getInfo() var S2VI_list = S2VI.toList(size) for (var n=0; n<size; n++) { var image = ee.Image(S2VI_list.get(n)) var date = ee.Date(image.get('system:time_start')).format('YYYY-MM-DD'); date = date.getInfo(); Export.image.toDrive({ image: image, description: ...


7

You need to add an interval of time to the date. This interval can can be hard coded or read from another field now() + to_interval('3 month') oldDate + to_interval( myIntervalIntegerValue || ' month')


6

I don't think there is a way to do that for a particular date field, and this link provided by Get Spatial confirms it. However, if you turn on Editor Tracking, it will create fields for: Creation Date Creator Last Edit Date Last Editor You have the option to name these fields to whatever you want. So, you could call the Created Date Field "Date Notified"...


6

I can confirm this behavior and I think the issue is only related to the Allow NULL values checkbox. With the Allow NULL values unchecked you will see that, when you click on the field you want to edit, it automatically displays the today's date and that's right because you can't store a NULL value in the field (obviously, you can change it later). With ...


6

Make a list of millisecond dates, and then use filter inList: var collection = ee.ImageCollection("MODIS/MYD11A1").select('LST_Day_1km'); var reference = collection.filterDate('2016-01-01', '2016-12-31') var datelist = ee.List(['2005-08-05','2009-09-01','2017-02-08']) .map(function(date){return ee.Date(date).millis()}) var newcol = collection.filter(ee....


6

Try using a combination of age() (which calculates the difference between the first date minus the second date, and returns an interval) wrapped in day() (which converts the interval to days as a number). So for example it is now 8 Nov 2018, 2:18 am. If my date field is 2018-10-25, I could find out the difference in days by doing: day(age(now(),"date")) ...


6

You can use strptime but it is probably easier to use pandas.to_datetime to convert the strings to datetimes. It is smarter/more flexible and can handle different string formats. Add a date field, create a function in Field Calculator or use da.UpdateCursor: import arcpy import pandas as pd table = r'C:\folder\Default.gdb\datedata' #Change to match your ...


6

If you have a field called Date which is a Date type, then you can use a "Categorized" style with this expression: to_datetime("Date") = maximum("Date") this will be 1 for features at the maximum date value and zero otherwise. Hit "Classify" and disable display of the zero category. Style the one category however: ...


5

You need to edit the properties of yours fields Date and Time in QGIS. Go to the properties of your layer. Select the Fields tab. In the line of your field (date and time), click on Line edit. Select Date/Time. And then you can specify the format of your date or time -> it must be the same as defined in Qt Designer! If the properties are the same in your ...


5

I have found the answer I need by using the advanced python field calculator. I set the following parameters; Field type:String Field length: 10 Global Expression: import time Formula: value = time.strftime("%Y-%m-%d") This gave me a new field with today's date added at the end.


5

You can use greater-than and less-than operators on dates, so something like this: "CHANGE_DATE" > date '2012-12-31 00:00:00' AND "CHANGE_DATE" < date '2014-01-01 00:00:00' Would work to grab all the dates for the year 2013. Note that the specific syntax of the query can change slightly depending on the data source. The above is for a file ...


5

From the Field Calculator, create a new integer field (let's call it Year) and assuming your date column is called Date, enter the following expression which takes 4 characters from the right-hand side of the value: right("Date", 4) Your new column should only contain the year. Now we should be able to use the Split Vector Layer tool from Vector> Data ...


5

Is this the STATS19 police accident open data? I've struggled with this before - as you say it's a huge data set. Joseph's answer is spot-on, but if you don't have the horsepower to deal with the data in the first place, I'd suggest importing into PostgreSQL and working with that, rather than trying your luck with the delimited files (I was just about able ...


5

You can create a new field with the field calculator and write the current date with a simple SQL command. Open the Layer properties Enable editing open field calculator 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 ...


5

Storing time alone is not supported, but dates can be stored without time. I just happened to be doing this - I have a date field with date/time stamps and I only want date stamps. I used these field calculator settings - replace DATEFIELD with your field name. Parser: Python Show Codeblock: checked Pre-Logic Script Code: def FindDate(date): if date ...


5

You can't compare a string with a datetime field (it will always be false). Instead create valid_from like this: date_after_month = datetime.datetime.today() + relativedelta(months=1) valid_from = date_after_month.replace(day=1,hour=0,minute=0,second=0,microsecond=0) This will create a datetime object with the day set to 1 (beginning of the month) and ...


5

You need to get today's date, and then format it as a string in the format you want. >>> todayDate = datetime.date.today().strftime("%Y%m%d") >>> print todayDate 20170216 You can incorporate this into your code: todayDate = datetime.date.today().strftime("%Y%m%d") arcpy.Statistics_AddressModel(StandAdd_Done_View__2_, todayDate, "...


5

You would have to use the code blocks. Here is an example of how it would work. I tested it and it works Expression: getSeason(!MONTH!) #Or the name of your field for months CodeBlock: def getSeason(month): if (month == "DECEMBER" or month == "JANUARY" or month == "FEBRUARY" or month == "MARCH"): return "WINTER" elif(month == "APRIL" ...


5

You can find out how many images are available per date with the frequencyHistogram reducer. Script with example roi. var ymd = ymdList(landsat) print(ee.List(ymd).reduce(ee.Reducer.frequencyHistogram()))


Only top voted, non community-wiki answers of a minimum length are eligible