0

I have a field in my database called 'Times', it's a date/time format and its format is set to 'short time'. In my database the date does not show, nor is it being add to the database as I know. It is only the time value. My DBGrid shows the time field with the time value and the date '12/30/1899'. How do I get rid of the date in my time field.

Here is the code I used to submit to the database. Get time value:

bookingtimes:= timeof(dttime.Time);

Submit to Database:

 tblbooking.FieldByName('Times').AsDateTime:=bookingtimes;

Example of DBGrid 'Times' column output:

12/30/1899 7:02:01AM
  • 1
    If you ask about setting display format, setup `DisplayFormat` e.g. to `hh:mm:ss` for your persistent field. Or declare a persistent calculated field and strip the date portion at calculation. Or remove the date portion inside a SQL command (by using `CAST`). I'm a bit confused about the used [tag:datetimepicker] tag here though. – Victoria Oct 03 '17 at 18:33
  • @Victoria Agreed `DateTimePicker` hasn't effect on it. – Ilyes Oct 03 '17 at 19:24

1 Answers1

4

If I understand what you mean this will work for you, just follow this steps:

  • This is your issue:

  • Double click on your table, and select Times field:

  • After you click on your field, go to the Object Inspector and find DisplayFormat property:

  • Write the format, in your case hh:mm:ss:

  • Now let's see the result:

That's it.

Ilyes
  • 14,640
  • 4
  • 29
  • 55
  • Thank you for the detailed step by step, however I do not have displayformat when I click on my Times field. What do I do to obtain that? My column returns as a TColumn rather than a TDateTimeField –  Oct 03 '17 at 19:41
  • @crackedlogic Did you right click on the table then hit `add all fields`? – Ilyes Oct 03 '17 at 19:46
  • Yes, then I clicked on the 'Times' field and moved to the object inspector. –  Oct 03 '17 at 19:48
  • @crackedlogic Can you edit your question and add a screenshot shows field editor next to the object inspector please. – Ilyes Oct 03 '17 at 19:50
  • I just realized my mistake, I have been looking at the dbgrid rather than the adotable –  Oct 03 '17 at 20:03
  • When i click on 'Add all fields' or 'Add fields' i get the message: 'Empty SQL Statements' – john_who_is_doe May 30 '18 at 06:26