0

I want to create custom format date and i'm struggling with that, need help.
Is it possible to create datetime format like this "02FEB2021 00:00:00" in Python ?

1
  • use datetime_object.strftime('%d%b%Y %H:%M:%S').upper() Commented Nov 4, 2021 at 18:08

1 Answer 1

0

Yes with a custom formatter

from datetime import datetime

fmt = "%d%b%Y %H:%M:%S"

date_str = datetime.now().strftime(fmt).upper()
print(date_str)  # 04NOV2021 19:07:50

date = datetime.strptime(date_str, fmt)
print(date)  # 2021-11-04 19:07:50
1
  • .upper() fix problem, thanks!
    – meteorolog
    Commented Nov 4, 2021 at 18:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.