Link to home
Start Free TrialLog in
Avatar of kretzschmar
kretzschmarFlag for Germany

asked on

qow 18: how to force a four digit year display for a db-date-value

hi experts,

i am restarting qow = question of the week :-)
(since it is possible now to post 25 pt. questions)

each week i will introduce a new simple? question.

now qow 18

sorry, top 15 experts, you are not allowed to solve this
q, only other can solve this question :-(

well the question is:

how to force a four digit year display
in data-aware controls
for a db-date-value?

(i've two simplew solutions in mind and some other)

each different solution may get 25 pts

let see

meikl ;-)
Avatar of DrDelphi
DrDelphi


Typecast the field as TDateTimeField:

TDateTimeField(query1.Fields[0]).DisplayFormat:='MMM DD,YYYY';



Double click in the Ttable or Tquery.

Right button of the mouse over the fields Editor.

Add Fields.

Write in the DisplayFormat something like this:
dd/mm/yyyy.

And all the Data aware Controls depending from this Table or Query will show the Date field as 30/12/2002...

Best Regards.
Marcos.

go to Start->Control Panel-> Regional Settings u configure your date here to 4 digits.

i work with TEdits

Edit1.Text:=Formatdatetime('dd/mm/yyyy',now) or
Edit1.Text:=Formatdatetime('dd/mm/yyyy',table1.fieldbyname('mydate').asdatetime);

Accept the answer if help you thanks

Avatar of kretzschmar

ASKER

hi jamiguel,

there is no need to answer the question,
since each solution gets points.

and its just not polite to answer a question,
when others already has given a solution
in previous comments

for the future, please,
do rather comment than answer a question

i reject your answer,
to keep this q open for other solutions

i count for you 1 solution
>go to Start->Control Panel-> Regional Settings u
>configure your date here to 4 digits.

for this
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',now) or
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',table1.fieldbyname('mydate').asdatetime);

as i talked about dbaware-controls, i will count this,
if you can also provide the other direction
?table1.fieldbyname('mydate').asdatetime := ...

if you can provide this, then it counts as your second solution, and you will get 50 pts

drdelphi, marcoszorrilla are counting both

waiting for other solutions

i have already two other solutions in mind,
additional to the given solutions here.

meikl ;-)
hi jamiguel,

there is no need to answer the question,
since each solution gets points.

and its just not polite to answer a question,
when others already has given a solution
in previous comments

for the future, please,
do rather comment than answer a question

i reject your answer,
to keep this q open for other solutions

i count for you 1 solution
>go to Start->Control Panel-> Regional Settings u
>configure your date here to 4 digits.

for this
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',now) or
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',table1.fieldbyname('mydate').asdatetime);

as i talked about dbaware-controls, i will count this,
if you can also provide the other direction
?table1.fieldbyname('mydate').asdatetime := ...

if you can provide this, then it counts as your second solution, and you will get 50 pts

drdelphi, marcoszorrilla are counting both

waiting for other solutions

i have already two other solutions in mind,
additional to the given solutions here.

meikl ;-)
hi jamiguel,

there is no need to answer the question,
since each solution gets points.

and its just not polite to answer a question,
when others already has given a solution
in previous comments

for the future, please,
do rather comment than answer a question

i reject your answer,
to keep this q open for other solutions

i count for you 1 solution
>go to Start->Control Panel-> Regional Settings u
>configure your date here to 4 digits.

for this
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',now) or
>Edit1.Text:=Formatdatetime('dd/mm/yyyy',table1.fieldbyname('mydate').asdatetime);

as i talked about dbaware-controls, i will count this,
if you can also provide the other direction
?table1.fieldbyname('mydate').asdatetime := ...

if you can provide this, then it counts as your second solution, and you will get 50 pts

drdelphi, marcoszorrilla are counting both

waiting for other solutions

i have already two other solutions in mind,
additional to the given solutions here.

meikl ;-)
:-( can't reject the answer, ex-ex seems to be a bit buggy
hu, rejected,, sorry for the thretimes-post ;-)

waiting for other solutions

i have already two other solutions in mind,
additional to the given solutions here.

meikl ;-)
I always save dates as string fields in my databases. Listening...
i have already two other solutions in mind,
additional to the given solutions here.

no one else?

geo, just listening?
its really not a hard question

closing thread on friday

meikl ;-)

Here's yet another:

procedure TForm1.MakeDateText(Sender: TField; var Text: String;DisplayText:Boolean);
begin
     if (Sender.DataType=ftDateTime) then Text:=FormatDateTime('YYYY DD,MM',StrToDateTime(Sender.AsString));
     Displaytext:=True;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DbEdit1.Field.OnGetText:=MakeDateText;
end;

well, drdelphi,
this was one of the two i had in mind,
but also here is the other direction needed
(because usual dataaware-controls are also for editing)

just provide a onSetText-method to transform back,
and you get additional 25 pts

one solution already left

meikl ;-)
You're making me work here!<g>

procedure TForm1.MakeDateText(Sender: TField; var Text: String;DisplayText:Boolean);
begin
    if (Sender.DataType=ftDateTime) then Text:=FormatDateTime('YYYY MMM DD',StrToDateTime(Sender.AsString));
    Displaytext:=True;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 DbEdit1.Field.OnGetText:=MakeDateText;
 DbEdit1.Field.OnSetText:=MakeTextDate;
end;



procedure TForm1.MakeTextDate(Sender: TField; const Text: String);
begin
   Sender.AsDateTime:=StrToDateTime(formatDatetime('mm/dd/yyyy',StrToDateTime(text)));
end;

I'm sure this works with dataaware components, though not tested.

In the Create in the application:


shortdateformat:='dd/mm/yyyy';




John.

ASKER CERTIFIED SOLUTION
Avatar of Johnch
Johnch

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yep johnch,
this was my last solution, i had in mind,
its the simplest, does affect all date-displays,
except the tdatetimepicker display,
and this only for the current app instance
(os is not affected)

drdelphi,
i'm just impressed, how much you work,
for 25 pts. :-))

well, someone with a courious solution?

closing thread tomorrow,
each solution gets 25 pts (A Graded)

jamiguel,
the other direction of your second part solution
is still missing. post it here until tomorrow and you get
25 pts for this solution also.

meikl ;-)
i grade this q,

because its the simplest clean solution

the others

DrDelphi 50 pts.
marcoszorrilla 25 pts.
jamiguel 25 pts.

may watch out for their points

thanks for participating on this quest

meikl ;-)
ok
in the component ttable or tquery i can make double click and add all fields(press mouse right click and see a popupmenu same: add fields,delete fields ...), chose the fields that we want see in the dbgrid and press button ok, i choose the field (of type datetime) and then press F11 in proeprty Dismplayformat of the field i can type: dd/mm/yyyy

other

query1.Fields[0].DisplayFormat:='dd/mm/yyyy';

thanks
:)