Question

I am not able to get datetime from TDateTimePicker in C++ builder ide. I am formatting it to show date and time but it shows only date it's because i think it's Kind property is set to dtkDate. is it possible to get date and time from this component ??

ShowMessage(deARV->DateTime.FormatString("dd.MM.yyyy HH:mm"));
Was it helpful?

Solution

A TDateTimePicker with its Kind property set to dtkDate does not have Time associated with it. If you need both a Date and Time, you have to use two separate TDateTimePicker controls, one set to dtkDate and the other set to dtkTime. You can then combine their two values together when needed, eg:

TDateTime dtDateTime = deARVDate->Date + deARVTime->Time;
ShowMessage(dtDateTime.FormatString("dd.MM.yyyy HH:mm"));

I have seen that sometimes this can cause garbage values in the unused portions of the TDateTime values, so I prefer to use this instead:

TDateTime dtDateTime;
ReplaceDate(dtDateTime, deARVDate->Date);
ReplaceTime(dtDateTime, deARVTime->Time);
ShowMessage(dtDateTime.FormatString("dd.MM.yyyy HH:mm"));

Or this:

TDateTime dtDateTime = DateOf(deARVDate->Date) + TimeOf(deARVTime->Time);
ShowMessage(dtDateTime.FormatString("dd.MM.yyyy HH:mm"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top