I created a shapefile with a string field with dates in the 02/22/2012 format and was able to convert it using the "Convert Time Field" tool after a couple tries.
On my successful attempt I created a new field of type date and then ran the date conversion tool.
For the custom format I used "MM/dd/yyyy". I also specified the newly created date field as the output time field.
I checked the method with errors in the strings and even a string like "2/5/12" was converted to 2/5/2012.
(My initial failures came because I assumed the tool would create a new date field for me, that didn't happen during my test.)
I hope this helps.
The reason that you are not able to save Time
related information in a shapefile
is that the Shapefile format, does not support Time as an attribute. They only support Date
fields. This is due to the fact that the shapefile uses an older specification of the dBase file (.dbf) to store the attribute table.
If you need to store time data, you are going to have to use one of the ESRI Geodatabase formats, either the Personal GDB
, or the File GDB
, for local storage. Even with these formats, there are limitations on how well Time
attribute fields are supported. This ESRI Help article discusses SQL query expressions, but also mentions what storage types support Time Attributes: SQL Reference for query expressions used in ArcGIS
Edit - To directly address your question of how to maintain your Time
data.
When you save data as a specific time format, for example, 12:30:05 PM
, this is stored, according to the SQL link above, as 1899-12-30 12:30:05
. This is why you are seeing a conversion in the time between Excel and the shapefile.
If you have been able to do this in the past, what was likely occurring, was that the cells containing your time data were not actually formatted as "Date/Time" in Excel, therefore, when converted to Shapefile, there was no conversion of the times
, and they were saved to a String
field.
If you want to convert Time data from Excel, and store it in a shapefile, you will need to save it to a Text field. This Help article discusses Supported Field formats, and discusses storing date/time as both a string or a number.
This next article discusses Converting string or numeric time values into date format
These articles should provide you with some workarounds if you have to maintain your data in the Shapefile format.
Best Answer
A Field Calculator expression tested in QGIS 3.16.16
which works like below: