Search code examples
pythonpycharmcalendarformat

How to get the month, day and year from Calendar.get_date separately in python?


I need the year, month and day separately, or simply convert it in datetime, because I need another format such as yyy-month-dd from the Calendar get_date method.

cal = Calendar(ventanaEvento, selectmode="day", year=2022, month=1, date=1)
cal.place(x=450, y=100)
print(cal.get_date())

prints: 1/19/22 month, day, year.

This just returns a string which I do not need, because I need the numbers separately or a different format: yyyy-mm-dd.

Thanks in advance.


Solution

  • from datetime import datetime
    date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    print(date)
    

    Y-year, m-month, d-day, H-hours, M-minutes, S-seconds