Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:13:19+00:00 2026-06-14T22:13:19+00:00

Sorry, I am very new to DbGrids. Should I use the query’s field editor

  • 0

Sorry, I am very new to DbGrids.

Should I use the query’s field editor and somehow add a new field that captures the TIMEDIFF and then just add that as a column in my DbGrid?

Or can/should I skip the field editor and somehow declare the TIMEDIFFF as a column?

For this table, I want a DbGrid with 4 columns : start time, end time, duration, description (run_id is the primary key & will not be displayed).

I am stumped as to how to get data into a ‘duration’ column …

mysql> describe  test_runs;
+------------------+-------------+------+-----+---------+----------------+
| Field            | Type        | Null | Key | Default | Extra          |
+------------------+-------------+------+-----+---------+----------------+
| run_id           | int(11)     | NO   | PRI | NULL    | auto_increment |
| start_time_stamp | timestamp   | YES  |     | NULL    |                |
| end_time_stamp   | timestamp   | YES  |     | NULL    |                |
| description      | varchar(64) | YES  |     | NULL    |                |
+------------------+-------------+------+-----+---------+----------------+
4 rows in set (0.37 sec)

[Update]
The query for the datasource is

SELECT start_time_stamp,
       end_time_stamp,
       TIMEDIFF(end_time_stamp, start_time_stamp) as duration,
       description

FROM test_runs ORDER BY start_time_stamp DESC

and when I execute it manually in MySql, I get

mysql> select TIMEDIFF(end_time_stamp, start_time_stamp) as duration FROM
+----------+
| duration |
+----------+
| NULL     |
| 00:04:43 |
| 00:00:13 |
| 00:00:06 |
| 00:00:04 |
+----------+
5 rows in set (0.00 sec)

but the corresponding column in the DB grid remains blank. Can anyone help? Thanks.


[Update] I am using AnyDac, if that helps. The query produces all fields, including the time difference, in MySql and also in the Delphi IDE when I use the AnYDac query editor and execute it.

The only problem is that I don’t see it in the DB grid at run time. I double click the DB grid at design time and the columns are correct. The FielName property is set to duration, which is retuned by the query shown above. It doesn’t exist in the database, but is calculated by the query; could that somehow be the problem??


[Aaaaaaaargh!!!] Someone tried to “improve” my code and set the query’s text programatically at run-time (as SELECT * FROM test_runs), thus overwriting my design time query!! Since the databse table does not have a duration field, none was shown in the DB grid.

Words were had, voices were rasied and now I must apolgize for wasting your time. Sorry.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:13:20+00:00Added an answer on June 14, 2026 at 10:13 pm

    I would create a calculated field in your Query and add that field to your DbGrid.

    so, as you say, with the Field Editor open for the query, right-click and select New Field (or press Ctrl-N). Give your new field a name (eg Duration), keep Component name default or rename if you desire. Set the Type as appropriate (DateTime most likely in this case) and set the Field Type to Calculated.

    Then, in the OnCalcFields event of your Query, set the value of that field to the value you want. eg:

    procedure TForm1.Query1CalcFields(DataSet: TDataSet);
    begin
      Dataset.FieldByName('description').AsDateTime :=
         DataSet.FieldByName('end_time_stamp').AsDateTime - 
         DataSet.FieldByName('start_time_stamp').AsDateTime;
    end;
    

    Or, you could also include the Duration as an extra field in your select query. Unfortunately I don’t have ready access to MySQL here, but it could be something like:

    select run_id, start_time_stamp, end_time_stamp, description, 
      (end_time_stamp - start_time_stamp) as duration from test_runs;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry that I am very new to the android development and now that I
Sorry I am very new to open graph and have been having difficulty to
I am very very new to JavaScript so sorry if this is really silly.
I'm very new to javascript and raphaelJS, so sorry for my messy code, but
Sorry if the question isn't correct, I'm very new in Objective-C. I understand why
I am very sorry to ask such a basic question but I am new
I am new to javascript so sorry I don't know very much. I have
[Sorry, I'm new in Python. Although it seems to be a very basic question,
Sorry for the newbie question but still very new to Ruby and Mongo. Not
Sorry if the question is very elementary, I am still very new to Haskell.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.