tkcalendar icon indicating copy to clipboard operation
tkcalendar copied to clipboard

DateEntry get_date() doesn't return correct selected date

Open TomiwaJoseph opened this issue 4 years ago • 2 comments

If year 1993-02-28 was selected in the DateEntry for example, the get_date() method returns 2093-02-28. If I use the get() method it returns correct date as string but I won't be able to know for example if 3/6/93 means 03-06-1993 or 03-06-2093. Please do help.

Thanks.

TomiwaJoseph avatar Mar 26 '21 20:03 TomiwaJoseph

Are you using the date_pattern attribute when making your DateEntry ? Perhaps I'm misunderstanding the problem

teauxfu avatar Apr 23 '21 04:04 teauxfu

This is 2 years later but still a problem... here is some code that produces the error:

import datetime
import tkinter as tk
from tkinter import ttk
from tkcalendar import DateEntry

def get_date():
    print(cal.get_date())   # prints '2050-01-01'

root = tk.Tk()
cal = DateEntry(root)
old_date = datetime.date(1950, 1, 1)
cal.set_date(old_date)
cal.pack(padx=10, pady=10)
ttk.Button(root, text='Get date', command=get_date).pack(padx=10, pady=10)

root.mainloop()

Is the only solution to set a date pattern?

adamantonio avatar Jan 29 '23 01:01 adamantonio