[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change Format of DBGrid display

Posted on 2003-12-07
8
Medium Priority
?
492 Views
Last Modified: 2010-04-05
Hi..

I would like to change the display in the DBGrid.. In the database, I keep a field named DatePay with field type Date. I use DBase as my database type. So, the display of the date will be normally in 1/1/2003 format. Now I want to display this table in the DBGrid, but I want to change the display of DatePay field into: 1 Jan 2003. Is there anyway I can do this? Thankss :)
0
Comment
Question by:pipinana2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 5

Accepted Solution

by:
snehanshu earned 200 total points
ID: 9894661
pipinana2002,
  Here's a code that works for me: I set the displayformat property of the table'sdate field to whatever is required.
  Alternatively, I tried setting shortdateformst to  'd mmm yyyy' and that worked too.
  You could set
  ShortDateFormat := 'd mmm yyyy';
in the application's main form's oncreate event.
  Hope that helps,
...Snehanshu

Alternate code, to set the display format of the table's field:

procedure TForm1.Button1Click(Sender: TObject);
begin
   MyTable.Insert;
   ShortDateFormat := 'dd/mm/yyyy';

//DBGrid shows 1 jan 2003 irrespective of shortdateformat due to:
   (MyTable.FieldByName('MyDate') as TDateTimeField).DisplayFormat := 'd mmm yyyy';

   MyTable.Fields[0].AsDateTime := StrToDate('01/01/2003');
   MyTable.Fields[1].AsString := 'Snehanshu';
   MyTable.Post;
   ShortDateFormat := 'yyyy/mm/dd';
end;
0
 

Author Comment

by:pipinana2002
ID: 9894720
Hi snehanshu

Thanks a lottttt for your helppp :) It works well.. Hehehehe.. U're very very greatt! :D
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9894748
pipinana2002,
  Glad to know I could help. Thank you for the grade and the kind words :-)
...Shu
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9895575
just to say,
there is no need to change the shortdateformat
--> just change the displayformat of the underlying field

meikl ;-)
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10539448
I was looking at my bookmarks today and read this.
Meikl,
>>just change the displayformat of the underlying field
Can you show me how?

Thanks,
...Shu
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10539475
for example (you can also use the dataset directly)
anywhere at startup, maybe in the afteropen-event of the dataset

TDateTimeField(dbgrid1.Datasource.Dataset.FieldByName('YourFieldName')).DisplayFormat := 'dd.mm.yyyy';

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10539485
to go with the question

TDateTimeField(dbgrid1.Datasource.Dataset.FieldByName('YourFieldName')).DisplayFormat := 'd mmm yyyy';

meikl ;-)
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10539508
Thanks Meikl!!

Pls post a comment here:
http://www.experts-exchange.com/Q_20910740.html

So that I can give you points.

...Shu
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question