Solved

TDateTimePicker: Returning TDateTime in Date Property

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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