Encode date

Hi Guy's,

I have a date field that is say 07/07/1999,
I want to take this date and modify it to 07/07/YYYY as now, so it should read 07/07/2000.


Asw  
LVL 1
AswAsked:
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.

intheCommented:
hi,
im not sure if this what your after but
are you want something like:


procedure TForm1.Button1Click(Sender: TObject);
begin
ShortDateFormat := 'dd/mm/yyyy';
label1.caption := datetostr(datetimepicker1.DateTime);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Date1,Date2 : TDateTime;
  Y,M,D : Word;
  begin
  ShortDateFormat := 'dd/mm/yyyy';
  Date2 := strtodate(label1.caption); //or your date field
  DecodeDate(Date2,Y,M,D);
  Date1 := EncodeDate(2000,M,D);
  Label1.Caption := DateToStr(Date1);
end;

confused me a bit but seemed to work,
i put the datetimepickers date to 7 july 1999 and click button 1 then click button 2 and caption changed from 07/07/1999 to 07/07/2000

hope it helps
Regards Barry
0
nicola65Commented:
procedure TForm1.Button1Click(Sender: TObject);
var
  //OldDate is your old date
  Today,NewDate,OldDate : TDateTime;
  M,D,Y,OldY : Word;
  begin
  // OldDate:=StrToDate('mm/dd/yyyy');
  Today := now;
  DecodeDate(Today,OldY,M,D);
  DecodeDate(OldDate,Y,M,D);
  NewDate := EncodeDate(OldY,M,D);
  ShowMessage(DateToStr(NewDate));
end;
0

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
intheCommented:
!!!!!!!!!$£%£$^£^%34
im sure a comment would suffice for the second time in 10 mins !
0
AswAuthor Commented:
Hi Nicola65,

Thanks for your help the points are yours.

Thanks Barry for your help, but Nicola65
did just what I needed.

Many Thanks
Asw
0
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
Delphi

From novice to tech pro — start learning today.