• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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  
0
Asw
Asked:
Asw
  • 2
1 Solution
 
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
 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now