Reputation: 2896
I am trying to encode datetime format for strings that are of the form: '06JAN2018' or '31DEC2017'.
I think this is format = '%d[xxxx]%Y' but I don't know how to encode the month portion of it.
Is there a list anywhere of every type of encoding possible for this?
Upvotes: 2
Views: 12630
Reputation: 40918
The list of these codes is in the datetime
module's strftime() and strptime() Behavior documentation.
%b
: Month as locale’s abbreviated name.
In your case, 06JAN2018
is %d%b%Y
.
If what you're actually looking to do is to encode a datetime object or Pandas/NumPy datetime array to strings, you'll probably need to do the uppercasing yourself:
>>> dt = datetime.datetime(2017, 12, 31)
>>> dt.strftime('%d%b%Y').upper() # or .str.upper() in Pandas
'31DEC2017'
Upvotes: 10