Misleading of date and time in tdatetimepicker

Source: Internet
Author: User
Delphi datetime, date, time tdatetimepicker
Datetimedatetimedatetimepicker

 

1. The datetime, date, and time storage methods are essentially double. The integer part represents the date, and the decimal part represents the time. For more information, see the "date/time" Storage Method in access"

Tdatetimepicker has the preceding three attributes.

2. Set the kind attribute of tdatetimepicker to dtkdate to display the date, and set the second kind to dtktime to display the time, but not at the same time.

3. Use datetimepicker. Date and time to get the value. Note: Use trunc to get the value of date and use frac to get the value of time.

4. date, time, and datetime of datetimepicker are equal.

The following is an example:

Add a tdatetimepicker, two tedit, and two buttons to a new project, and set the Event code for the two buttons as follows:

{Datetimepicker1: 13:00:00}
Procedure tform1.button1click (Sender: tobject); // extract the date part and determine its value
VaR
T: tdatetime;

Begin
T: = datetimepicker1.date;

Edit1.text: = datetimetostr (t );
End;


Procedure tform1.button2click (Sender: tobject); // you can determine whether date and datetime are equal.

Begin

If datetimepicker1.time = datetimepicker1.datetime then
Begin
Edit2.text: = 'Equality'
End
Else
Begin
Edit2.text: = 'unequal ';
End;

End;

We can see that although only date or time is taken in our code, their values and datetime values are equal.

So if you use the following code

{Datetimepicker1: 13:00:00}
Procedure tform1.button1click (Sender: tobject); // extract the date part and determine its value
VaR
T: tdatetime;

Begin
T: = datetimepicker1.date + datetimepicker1.time;

// T: = trunc (datetimepicker1.date) + frac (datetimepicker1.time); // This is the date and time of datetimepicker1.

Edit1.text: = datetimetostr (t );
End;

Result: 2120-6-21 2:00:00

This is equivalent to multiplying the time and date of datetimepicker1 by 2. It does not mean that the date + time of datetimerpicker is equal to datetime.

However, if you use trunc to take the integer part and add frac to take the fractional part, the sum obtained by the two will be equal to the original sum.

Refer:

Http://ifso.iteye.com/blog/1752420

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.