Solved

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

Posted on 2002-06-24
19
331 Views
Last Modified: 2010-04-04
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 ;-)
0
Comment
Question by:kretzschmar
  • 10
  • 3
  • 2
  • +3
19 Comments
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility

Typecast the field as TDateTimeField:

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



0
 
LVL 3

Expert Comment

by:marcoszorrilla
Comment Utility
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.

0
 

Expert Comment

by:jamiguel
Comment Utility
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

0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
:-( can't reject the answer, ex-ex seems to be a bit buggy
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
I always save dates as string fields in my databases. Listening...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)

0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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;

0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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;

0
 
LVL 1

Expert Comment

by:Johnch
Comment Utility
I'm sure this works with dataaware components, though not tested.

In the Create in the application:


shortdateformat:='dd/mm/yyyy';




John.

0
 
LVL 1

Accepted Solution

by:
Johnch earned 25 total points
Comment Utility
I'm sure this works with dataaware components, though not tested.

In the Create in the application:


shortdateformat:='dd/mm/yyyy';




John.

0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
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 ;-)
0
 

Expert Comment

by:jamiguel
Comment Utility
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
:)
0
 
LVL 27

Author Comment

by:kretzschmar
Comment Utility
already commented by drdelphi, jamiguel

jamiguel, get your points at
http://www.experts-exchange.com/delphi/Q_20318114.html

marcoszorrilla, get your points at
http://www.experts-exchange.com/delphi/Q_20318113.html

meikl ;-)

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now