Recent

Author Topic: [SOLVED] How to get time field to display correctly in DBGrid?  (Read 8073 times)

dodgebros

  • Full Member
  • ***
  • Posts: 169
I have a TMaskEdit with the mask "!90:00<LL;1;_" .  The time entered here, such as 09:33pm, gets written to a field with data type of "Time" in a Firebird embeded database, version 2.5.2.

I also have a TDBGrid with column that display this Time field.  Strange thing is, I enter the time in 12 hour format and the TDBGrid displays it in 24 hour format.  I would like the time to be displayed in 12 hour format in the TDBGrid.

I noticed there is a property called DisplayFormat for each of the columns in the TDBGrid but I can't seem to find any information as to what goes in this property. 

Would setting the DisplayFormat property allow me to display the time the way I want to?  If yes, then what do I enter there?  If no, then is there another way to solution?

Thanks,
TD
« Last Edit: April 22, 2015, 06:23:35 pm by dodgebros »

balazsszekely

  • Guest
Re: How to get time field to display correctly in DBGrid?
« Reply #1 on: April 22, 2015, 04:02:17 pm »
Doubleclick the query, select the time field. OnGetText event, set aText value with FormatDateTime

dodgebros

  • Full Member
  • ***
  • Posts: 169
Re: How to get time field to display correctly in DBGrid?
« Reply #2 on: April 22, 2015, 04:26:47 pm »
Quote
Doubleclick the query, select the time field. OnGetText event, set aText value with FormatDateTime

Thanks for helping but I am new to Lazarus and FPC.  I am not sure what you mean by Doubleclick the query, what query?  What has the event OnGetText? Also, is FormatdateTime a function?

Thanks for helping,
TD

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: How to get time field to display correctly in DBGrid?
« Reply #3 on: April 22, 2015, 05:11:38 pm »
I noticed there is a property called DisplayFormat for each of the columns in the TDBGrid but I can't seem to find any information as to what goes in this property. 
I think it follows the same format as TDateTimeField.Displayformat.

The help of Lazarus is not that elaborate but here is the one from Delphi:
http://docwiki.embarcadero.com/Libraries/XE8/en/Data.DB.TDateTimeField.DisplayFormat

Does setting the Displayformat for that column to hh:mm am/pm help?

dodgebros

  • Full Member
  • ***
  • Posts: 169
Re: How to get time field to display correctly in DBGrid?
« Reply #4 on: April 22, 2015, 05:35:07 pm »
YES !  I'll checkout the link also.

I noticed that some posting have the word [SOLVED] at the beginning of their subject line.  Should I be doing that to my posting that are resolved, such as this one?  Do I just manually add the phrase [SOLVED]?

Thanks rvk!
TD
« Last Edit: April 22, 2015, 05:40:25 pm by dodgebros »

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: How to get time field to display correctly in DBGrid?
« Reply #5 on: April 22, 2015, 05:59:08 pm »
If you want to, you can edit the title of your first post and add [SOLVED] or [CLOSED] in front of it so others can see it's solved.

You could also lock the thread in options but you should only do that when a topic derails (bad comments etc.). Doing so now would only prevent other useful comments (but it's nice to know of the possibility).

dodgebros

  • Full Member
  • ***
  • Posts: 169
Re: How to get time field to display correctly in DBGrid?
« Reply #6 on: April 22, 2015, 06:23:00 pm »
Thanks rvk

balazsszekely

  • Guest
Re: How to get time field to display correctly in DBGrid?
« Reply #7 on: April 22, 2015, 06:23:30 pm »
OnGetText allow you more flexibility, although in this particular case rvk solution is better.
https://youtu.be/2p0klt8E4GA

 

TinyPortal © 2005-2018