1

When printing dates in the datetime module of Python 3.6, they look like:

>> from datetime.date import date
>> print(date(2018,1,30))
2018-01-30

Is it possible to change the format of the output of print() for datetime.date objects?

My desired outcome is:

>> print(date(2018,1,30))
30/01/18
J-J
  • 219
  • 2
  • 7
  • Possible duplicate of [How do I turn a python datetime into a string, with readable format date?](https://stackoverflow.com/questions/2158347/how-do-i-turn-a-python-datetime-into-a-string-with-readable-format-date) – Patrick Haugh Oct 29 '18 at 17:24
  • 3
    Specifically in this case: `print(date(2018,1,30).strftime("%d/%m/%y"))` – Patrick Haugh Oct 29 '18 at 17:24

1 Answers1

2

You can use datetime formatting function - strftime - taking a formatting string described in detail here.

You may also want to review Advanced date formatting from the following answer: How to print a date in a regular format?

sophros
  • 14,672
  • 11
  • 46
  • 75