Hot answers tagged

15

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


12

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


12

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 " ) ...


10

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

Eric’s Complete Guide To VT_DATE is a good guide if you are asking what I think you are asking. From here, you can get the string you want fairly easily in Python using datetime: import datetime new_dt = datetime.datetime(1899, 12, 30) + datetime.timedelta(days=41256.260799) formatted_string = new_dt.time().strftime("%H:%S") That should be pretty easy to ...


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

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


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

The syntax varies depending on where the data is being fetched from (file gdb, shapefile, personal gdb, Oracle, DB2, etc.). File Geodatabase, shapefiles, and file-based data such as dbf files: Everything in May: EXTRACT(MONTH FROM "MyDate") = 05 Before noon: EXTRACT(HOUR FROM "MyDate") < 12 Personal Geodatabase (.mdb): DATEPART("m", [MyDate]) = ...


7

This python field calculator script should work: def checkValue(field): myMonth = int(field.split('/')[0]) myYear = field.split('/')[2] if myMonth <=3: return 'Q1-' + myYear elif myMonth >= 4 and myMonth <=6: return 'Q2-' + myYear elif myMonth >=7 and myMonth <=9: return 'Q3-' + myYear else: return 'Q4-' + myYear ...


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

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.


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


5

You can use a One-to-many relationship from a shapefile ("one") to a table ("many"). Store all data that is unique for each facility in a shapefile: facility-id, Geometry, type, lat, log, ... Store data with one or more values for each facility in a second table e.g. *.dbf (not in a shape file!): facility-id, start-date, ... Relate (not join!) the ...


5

Here's a way using integer division: def checkValue(field): m,d,y=field.split('/') #assumes date in some backward MM/DD/YYYY format, what's with that? ;) q=(int(m)-1)//3 + 1 return 'Q%s - %s'%(q,y)


5

The way I have done this is as follows: - Add a column to your attribute table (ie: Date, Text, 10 characters) - Open the layer properties window and navigate to the Fields tab - On the Date line under the Edit widget, change it from Line edit to Calender - To add a date to the attribute, double click the Date field record in the attribute table and ...


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

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


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

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")) ...


5

Bring back Field Format to default (yyyy-MM-dd) setting and customize the Widget Display only.


5

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


4

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


4

I take no credit for the following Python snippet, which is taken from an ESRI idea found by Googling 'convert from julian to calendar date arcgis'. As trivia, they mention the data they were working with came from the FAA. There is also mention of data coming over from Excel in that format despite being entered differently. I apologize if my cut/paste ...


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