i use datepart() to extract year and month from current date and populate a field with "YYYYMM". but month parameter in datepart function doesnt allow setting it to always have two digits.
how can i extract month as MM as default? (for example March would be '03' instade of '3')
thanks
ofer
Does the following expression (Python Parser) work for you on a TEXT field?
str(time.strftime('%Y%m'))
If it doesn't, please provide a few more details
- What type of feature class (Shapefile, File GDB Feature Class, Enterprise FC-Oracle, PostgreSQL, SQL Server, etc.)?
- What expression have you got so far? Screenshot would help.
- Version of ArcGIS Pro?
Calculate Field Python examples—ArcGIS Pro | Documentation has examples
Expression:
!field1!.strftime("%m/%d/%Y, %H:%M:%S")
shows all the parts and the result
'02/22/2021, 10:15:00'
so as Jayanta says, you just need to parse the bits in the order you want
!field1!.strftime("%Y%m")
Where field1 is your field containing the data and your output field is a text field.
Note datetime and time are always available in the field calculator