Solved

TDateTimePicker: Returning TDateTime in Date Property

Posted on 2006-11-15
3
275 Views
Last Modified: 2011-10-03
Hi there,

Can anyone tell me how I can get the TDateTimePicker to return ONLY the date portion in the Date property?  It's returning the time fraction as well.

Just so you know, I have just replaced an old control with this one, and it's used in around 250 places within the application, so I really don't want to be changing to much to get it to work. All I'd like is when I go DateTimePicker1.Date, it'd return 39037, not 39037.686077.

I was under the impression the Date property is supposed to do that.  But it's not.  It's almost like it's a TDateTime.

Thanks for your help.

Pag.
0
Comment
Question by:PAG_Promax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 100 total points
ID: 17953702
Pag,

Its due to the inheritence from the TCommonCalendar control, which returns the date as a datetime value. To handle this, you can subclass its usage in the units used by doing the following:

// Eg.
type
  TDateTimePicker   =  class(ComCtrls.TDateTimePicker)
  protected
     function       GetDate: TDateTime;
  public
     property       Date: TDateTime read GetDate;
  end;

type
  TForm1 = class(TForm)
    Button1: TButton;
    DateTimePicker1: TDateTimePicker;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

function TDateTimePicker.GetDate: TDateTime;
begin
  result:=Trunc(inherited Date);
end;

.... remainder of unit code...

end.

----

Regards,
Russell

0
 
LVL 6

Assisted Solution

by:Hardi
Hardi earned 25 total points
ID: 17962501
You have to use DateOf(DateTimePicker1.Date) to get 39037.
But since you have it in 250 places, use Russell's solution :-)
0
 

Author Comment

by:PAG_Promax
ID: 18033242
Thanks, Russell.  That worked well for me.

And thanks for the info about the DateOf function too, Hardi.  I didnt know about that one.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question