{"record":{"id":"ffd7b01f7cca5101","repo":"django/django","slug":"unable-to-retrieve-date-time-information-from-th","errorCode":null,"errorMessage":"Unable to retrieve date & time information from the field.","messagePattern":"Unable to retrieve date & time information from the field\\.","errorType":"exception","errorClass":"GDALException","httpStatus":null,"severity":"error","filePath":"django/contrib/gis/gdal/field.py","lineNumber":92,"sourceCode":"        if not self.is_set:\n            return None\n        yy, mm, dd, hh, mn, tz = [c_int() for _ in range(6)]\n        ss = c_float()\n        status = capi.get_field_as_datetime_x(\n            self._feat.ptr,\n            self._index,\n            byref(yy),\n            byref(mm),\n            byref(dd),\n            byref(hh),\n            byref(mn),\n            byref(ss),\n            byref(tz),\n        )\n        if status:\n            return (yy, mm, dd, hh, mn, ss, tz)\n        else:\n            raise GDALException(\n                \"Unable to retrieve date & time information from the field.\"\n            )\n\n    # #### Field Properties ####\n    @property\n    def is_set(self):\n        \"Return True if the value of this field isn't null, False otherwise.\"\n        return capi.is_field_set(self._feat.ptr, self._index)\n\n    @property\n    def name(self):\n        \"Return the name of this Field.\"\n        name = capi.get_field_name(self.ptr)\n        return force_str(name, encoding=self._feat.encoding, strings_only=True)\n\n    @property\n    def precision(self):\n        \"Return the precision of this Field.\"","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/contrib/gis/gdal/field.py#L74-L110","documentation":"Raised by Field.as_datetime (django/contrib/gis/gdal/field.py:92) as a GDALException when OGR_F_GetFieldAsDateTimeEx returns a falsy status, meaning GDAL could not interpret the field's contents as a date/time. This surfaces when accessing the `.value` of an OFTDate/OFTTime/OFTDateTime field whose stored bytes are not parseable as a datetime.","triggerScenarios":"A date field containing an empty string, '0000-00-00', a malformed timestamp, or non-date text. A field whose declared type is OFTDateTime but whose actual content was written by a buggy exporter. Accessing `.value` on such a field.","commonSituations":"Shapefile/DBF date columns with null/zero placeholders ('00000000'). GeoPackage datetime fields with timezone formats the GDAL build doesn't parse. Corrupt date cells from spreadsheet-to-GIS conversions. Note: the OFTDate/OFTTime/OFTDateTime `.value` properties catch GDALException and return None, so this error typically surfaces only when calling as_datetime() directly.","solutions":["Use `.value` (which returns None on failure) instead of `.as_datetime()` directly.","Pre-screen the field's raw string value with `field.as_string()` and your own parser.","Repair the source data: replace zero/null dates with valid values or NULL.","Upgrade GDAL; newer versions parse more datetime formats."],"exampleFix":"// before\nyy, mm, dd, hh, mn, ss, tz = field.as_datetime()   # raises on bad date\n// after\nval = field.value                                    # returns None gracefully\nif val is None:\n    val = parse_fallback(field.as_string())","handlingStrategy":"fallback","validationCode":"raw = field.as_string()\nis_plausible_date = bool(raw and raw.strip() not in ('', '0000-00-00', '00000000'))\nif not is_plausible_date:\n    return None  # skip as_datetime on null/zero dates\nreturn field.as_datetime()","typeGuard":"def looks_like_date(raw: str) -> bool:\n    return bool(raw) and raw.strip() not in ('', '0000-00-00', '00000000')","tryCatchPattern":"from django.contrib.gis.gdal.error import GDALException\ntry:\n    components = field.as_datetime()\nexcept GDALException:\n    components = None  # fall back to raw string parsing\nif components is None:\n    parsed = parse_fallback(field.as_string())","preventionTips":["Prefer field.value over field.as_datetime() — it returns None on failure.","Pre-screen date fields with as_string() for null/zero placeholders.","Clean source data: replace '0000-00-00' with NULL before reading."],"tags":["gis","gdal","ogr","field","datetime","data-quality"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}