Solved

TDateTimePicker: Returning TDateTime in Date Property

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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