In C ++ builder, how does DBGrid display only the time or date?

Source: Internet
Author: User

If the database is MSSQL, if only the time or date is inserted, the database inserts the complete date and time format by default, in this way, all the date and time are displayed by default when you use the data sensing control to display the time. However, sometimes you only want to display the date or only the time, but the default display format obviously does not meet the requirements.

So how can we make the data-aware control show only the date or only the time? In fact, you can set the dispalyformat format of the data source of the data sensing control to achieve this goal.

Assume that a time data is displayed using the adoconnection, adoquery, datasource, and DBGrid controls. Set the connection between adoconnection and the database, write the SQL statement of adoquery, and set the relationship between the four. The result is as follows:

However, this is obviously not the expected result, but only the time is displayed.

You can set the displayformat of the data source field. The specific method is as follows:

1. Right-click the data source control and select "fields Editor"

2. In the open editor window, select "add all fields" to select all fields or "add fields" to select the fields to be displayed.

3. Select the selected field and write the time display format in "displayformat" in the attribute bar.

4. Now, the settings are complete. Run the program again. The following page is displayed.

This is exactly what you want to achieve.

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.