Format Python datetime as string with strftime

Want to format a #Python datetime as a string? Use strftime: dt = datetime.datetime(2026, 4, 1, 13, 15, 17) dt.strftime('%Y-%m-%d') # '2026-04-01' dt.strftime('%Y-%m-%d %H:%M:%S') # '2026-04-01 13:15:17' dt.strftime('%y-%B-%e %H:%M:%S') # '26-April- 1 13:15:17'

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories