Solved

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

Posted on 2002-06-24
19
334 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
ID: 7105130

Typecast the field as TDateTimeField:

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



0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 7105274
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
ID: 7106476
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
ID: 7106514
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
ID: 7106516
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
ID: 7106519
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
ID: 7106521
:-( can't reject the answer, ex-ex seems to be a bit buggy
0
 
LVL 27

Author Comment

by:kretzschmar
ID: 7106522
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
ID: 7107077
I always save dates as string fields in my databases. Listening...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Author Comment

by:kretzschmar
ID: 7111542
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
ID: 7111933
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
ID: 7112798
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
ID: 7113640
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
ID: 7114030
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
ID: 7114031
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
ID: 7114678
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
ID: 7121104
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
ID: 7122559
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
ID: 7125998
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 88
How to call a form that is in a DLL  from an application? 13 65
Delphi 2 49
Adoquery sql  left join does not work 25 80
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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