AnsweredAssumed Answered

Converting date to string and combining fields using Python

Question asked by cserratos@nps.gov_nps on Jul 6, 2018
Latest reply on Jul 6, 2018 by cserratos@nps.gov_nps

I'm trying to get more familiar with ArcGIS Pro and by necessity, Python. I have multiple feature classes that are assigned a unique identifier that combines the location and date/time that the data were collected in the format "PARK_YYYYMMDD_HHMMSS". "PARK" comes from a data field [Park_Unit] with a coded domain and date/time from a date field [TRT_BEG_TM]. I'm trying to get it to work using Python but I can't wrap my head around functions and syntax. Here's the VB Script expression I've been using in ArcMap for reference. Thanks in advance.

 

Pre-Logic Script Code:

strYear= Year( [TRT_BEG_TM] )
strMonth= Month ( [TRT_BEG_TM] )
strDay = Day( [TRT_BEG_TM] )
strHour = Hour( [TRT_BEG_TM] )
strMin = Minute( [TRT_BEG_TM] )
strSec = Second( [TRT_BEG_TM] )
If strDay < 10 Then
  strDay = "0"& strDay
end if
  If strMonth < 10 Then
strMonth = "0" & strMonth
end if
If strHour < 10 Then
  strHour = "0" & strHour
end if
If strMin < 10 Then
  strMin = "0" & strMin
end if
If strSec < 10 Then
  strSec = "0" & strSec
end if
Formatteddate= strYear & strMonth & strDay & strHour & strMin & strSec

 

LOC_NM=

[PARK_UNIT] &"_"& left(Formatteddate,8) & "_" & right(Formatteddate,6)

Outcomes