Domanda

I have a TDateTimePicker with Kind=dtkDate on my form.
When the form opens I do

TDateTimePicker.date := Date

I have a var lStartDay : TDateTime; and do

lStartDay := DatePickerStart.Date;

I have not touched the TDateTimePicker in the user interface.

Now, the evaluate/modify (Ctrl-F7) dialog and the watch list (and the cursor hovering over the code) show DatePickerStart.Date as 8-1-2014, but StartDate is 8-1-2014 15:00:00

When I edit the watch value DatePickerStart.Date to not use the visualizer it shows 41647,625 (it took me some time to find that!)

Why does TDateTimePicker.Date contain a time fraction?

È stato utile?

Soluzione

Answering my own question to prevent others from tumbling into the same pit:

It turns out that when you place a TDateTimePicker on your form, the Time property gets filled with the current time and this always gets returned as part of DatePickerStart.Date. Mine was obviously placed on the form at 15:00:00

The time remains 'in' even when you use the TDateTimePicker so select another date.

So, to fix this: Clear the Time property at design time (it becomes 00:00:00) and/or always use Trunc(TDateTimePicker.Date) or DateOf(TDateTimePicker.Date) when you really only need the date.

Of itself, TDateTimePicker.Date does not return the date!.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top