Solved

TDateTimePicker: Returning TDateTime in Date Property

Posted on 2006-11-15
3
269 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
3 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now