Change Format of DBGrid display


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 :)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  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,

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

procedure TForm1.Button1Click(Sender: TObject);
   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';
   ShortDateFormat := 'yyyy/mm/dd';

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pipinana2002Author Commented:
Hi snehanshu

Thanks a lottttt for your helppp :) It works well.. Hehehehe.. U're very very greatt! :D
  Glad to know I could help. Thank you for the grade and the kind words :-)
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

just to say,
there is no need to change the shortdateformat
--> just change the displayformat of the underlying field

meikl ;-)
I was looking at my bookmarks today and read this.
>>just change the displayformat of the underlying field
Can you show me how?

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 := '';

meikl ;-)
to go with the question

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

meikl ;-)
Thanks Meikl!!

Pls post a comment here:

So that I can give you points.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.