Solved

TDateTimePicker: Returning TDateTime in Date Property

Posted on 2006-11-15
3
277 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

Suggested Solutions

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…
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 shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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