Search code examples
c++datetimepickerc++buildervclmonthcalendar

How to get date (day/month/year) from MonthCalendar in C++ Builder 6?


I'm creating an age counter app, but I couldn't use the date, which is user chose from the calendar. How can I use the day/month/year specified in MonthCalendar in my program?

monthcalendar


Solution

  • TMonthCalendar has a Date property, which returns the user's selected date as a TDateTime value. You can extract the individual month, day, and year values from that, if needed, by using the TDateTime::DecodeDate() method.

    TDateTime dtSelected = MonthCalendar1->Date;
    Word wYear, wMonth, wDay;
    dtSelected.DecodeDate(&wYear, &wMonth, &wDay);
    ...