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


9

Expression to_datetime("Date_Field") + to_interval('10 hours') will add 10 hours to the "Date_Field". I have not tested fully, but it seems to_interval() accepts month(s) day(s) hour(s) and their combinations such as '1 day 2 hours'.


9

The easiest way to find out how to reproduce something in python is to run it once in ArcMap using the ArcToolbox tool (or in this case, the Field Calculator), and then choosing Copy Python Snippet from the geoprocessing results. Run the Field Calculator Open the Results pane (Geoprocessing > Results) Find the corresponding tool results, right-click and ...


9

As joseph said in comment you can't store date and time in a single field of a shapefile, you could : -use a string field (as Joseph said) -use two field (one for date and one for time...) -use another file format that support DateTime fieldtype to store your data


6

The right way is probably to create a child (related) table with a record for each opening interval. For example: Main (store) table: +----+------+ | id | name | +----+------+ | 1 | Foo | +----+------+ | 2 | Bar | +----+------+ opening hours table: +----+----------+-----+-------+-------+ | id | store_id | day | open | close | +----+----------+-----+--...


5

Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field: with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor: for row in cursor: print row[0], type(row[0]) 2014-07-18 06:03:05 <type 'datetime.datetime'> 2014-07-17 00:00:00 <type '...


5

Arcpy has a built-in function to do this kind of conversion: Convert Time Field. It's mentioned in the first ArcGIS Help link in your question. It can take an ArcGIS date field and convert it to several datatypes, including integer. Here's the syntax: ConvertTimeField_management (in_table, input_time_field, {input_time_format}, output_time_field, {...


5

I tried to use a csvt file (like documented at https://anitagraser.com/2011/03/07/how-to-specify-data-types-of-csv-columns-for-use-in-qgis/) to force the type when adding "Delimited text layer". If I tick the "Detect field types" or not, I get the same issue as you: no clues why too... To get what I want, I have to go another way. I create your sample file ...


4

This line here creates a timedelta object: # Calculates the difference between firstLogdt and lastLogdt timeDiff = lastLogdt - firstLogdt A datetime object is different type than a timedelta. The timedelta object doesn't fit with a date field (hence the TypeError). You could instead create a double field instead of a date field, and store the difference ...


4

Try this code. !UT! is a date field in my FeatureClass storing date and time in the format of "22/11/2012 11:23:30" import datetime from dateutil import parser def convert(ut): dateobject = parser.parse(ut) return datetime.datetime.strftime(dateobject,'%H:%M:%S') The Expression you apply to your string field in the Field Calculator would be convert(!...


4

So I figured it out - @Yanes was close but instead of three sets of double quotes, it needed to be double-single-double. So the following script works: -- Turn ReportsTable into a View Table arcpy.MakeTableView_management(ReportsTable, ViewTable) -- Get start and end times for report start_time= datetime.timedelta(hours = 24) end_time = datetime....


4

This is a little off topic as it has to do with pure python (or VB). Using the python parser you can get the current time with the function: datetime.datetime.now().strftime('%H:%M') # use '%h:%M' for 12 hour time Have a read of strftime behavior, note that this will be a string, not a datetime, so can only be stored in a string field.


4

You can use the UpdateCursor to read the date field and update the week field: UpdateCursor establishes read-write access to records returned from a feature class or table. The code can be executed in the Python window. You need to change the name of the feature class and fields to match your data: import arcpy,datetime with arcpy.da.UpdateCursor("...


4

If you need this only as a temporal solution for testing purposes you can use Convert Time Field tool to create text field with custom formatting. Every time DATE field is changed you have to rerun this tool. As mentioned in Fundamentals of date fields: Date fields vary between data source types, and their display depends on your system locale. Settings on ...


4

LiDAR times often come in GPS time or time since the GPS epoch. Here is a stack exchange link with more detail (What is a GPS epoch?) This look like GPS seconds. Your data should also include a column of data that shows the GPS week You can use the week and seconds data to convert the pulse time to human-readable time using a website like GPS Time ...


4

This is a limitation of Shapefiles which cannot store both date and time in the same field. The ESRI documentation at https://pro.arcgis.com/en/pro-app/help/data/tables/date-fields.htm says: When calculating date fields, the field calculator uses Python datetime functions. Some of the functions support datetime yyyy-mm-dd hh:mm:ss AM or PM. However, for ...


3

See my blog on "I've Saved Time in a Bottle. How Do I Get it Back Out? - Doing More with Date Fields Using the Field Calculator and Python" As stupid as it may seem, when you use the Python option in the Field Calculator on a date field, the date is converted to a string and does not have any native date functionality. You have to convert it back to a ...


3

arcpy.CalculateField_management(fc, "time", "!DATE!.split(' ')[1]", "PYTHON") This uses Python to split the string at the space (which returns a list containing the date as a string and the time as a string), and populates the field with the second item in the list, which is the time.


3

Try this out: arc.ConvertTimeField_management("TEST_TIME","Date__Time","yyyyMMdd HH:mm:ss","Date_Conv","DATE") There are two issues with your code: Since your input local is not the U.S. (01033), the time gets messed up, so just leave that out When you chose "DATE" for your output time type, you do not get to chose your "locale", since that is handled by ...


3

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


3

You appear to be confusing "attributes" and "values". By selecting the [Data Type] as "date" you are informing ArcGIS that this field or column will contain dates. You have not told ArcGIS what those dates are. If you were to add another field or column and set the [Data Type] as "text" would you expect Arc to populate it with the word "text"? The [Data ...


3

You don't need the triple quotes at the start and the end. Try: where_clause = "date > date '%s' AND date < date '%s'" %(date_1,end_date)


3

The code below demonstrates how to get this to work using code very similar to that in the question, but I recommend also reviewing the detailed explanation that follows in order to understand why it works: import arcpy dmyString = "01.07.2015" d,m,Y = dmyString.split(".") dmyDate = datetime.datetime(int(Y),int(m),int(d)) epoch = datetime.datetime(1899, 12,...


3

Here is a code sample from the documentation. Here, they assign dt to a variable. You need to import datetime and then create a dt variable from your datetime value. Look how they do it in the sample and check out the context from the rest of it for more information. >>> from datetime import datetime, date, time >>> # Using datetime....


3

The way I just did this assumes that you are using a file geodatabase features class, with an OBJECTID field that starts at 1. I've called my date field DateField so change that for yours. Parser: Python Code Block: def inc162secs(oid): startDataObj = datetime.datetime.strptime("30/01/2015 18:30:00", "%d/%m/%Y %H:%M:%S") return startDataObj + ...


3

With the help of @MichaelMiles-Stimson the Pre-Logic Script Code I ended up using was: def date_only(datetimeVal): datePart = datetimeVal.split(" ")[0] return datePart The reason I needed to do it this way rather than the precise method used by @blah238 in the answer to the other question was that the Field Calculator performs a datetime to ...


3

You just don't quite have the quotes right in your expression.You need double quotes around your datetime. Also, you shouldn't have !DateTime! = as part of it. Try: arcpy.CalculateField_management(out_path_shp, "DateTime", '"' + date_time + '"', "PYTHON_9.3")


3

When you get the value !DATE_VAL! ArcMap returns a string. You have to therefore construct a datetime object in order to add a timedelta object. To do this, you need to know the format of the string returned by your Date field. By default, ArcMap uses your system date format. In my case, I have the DATE_VAL field which returns dates in the format 14/10/2016 ...


3

You could try this. Its post manipulation though not sure how to get the right values to begin with. import arcpy import datetime fldName = 'ORIGDTTIME' fc = 'featureclass' myList = set([(row.getValue(fldName).time()).strftime("%I:%M %p") for row in arcpy.SearchCursor(fc) if row]) print myList Using test data import datetime list = [datetime.datetime(...


3

I created some other data starting from yours and it seems possible to use the datetime field for a categorized field. From Properties > Style, I set these options: and I got this: Is this the expected result or I'm missing something?


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