Jump to content
abdellahmehdi

date

Recommended Posts

You didn't mention whether this is a date, string, or integer value, so I'm just going to assume using the Date function:

FormatDateTime('yy', Date)

 

  • Like 1

Share this post


Link to post

I have a few overloads for YY conversion, mostly used to convert from imported text files:

 

function GetYYFromDate(const aDate: TDate): integer; overload;
begin
  // 01/01/2019 -> 19
  Result := FormatDateTime('yy', aDate).ToInteger;
end;

function GetYYFromDate(const aDate: TDateTime): integer; overload;
begin
  // 01/01/2019 01:01:01 -> 19
  Result := FormatDateTime('yy', aDate).ToInteger;
end;

function GetYYFromDate(const aDate: string): integer; overload;
begin
  // '01/01/2019' -> 19
  Result := Copy(aDate, Length(aDate) - 2, Length(aDate)).ToInteger;
end;

function GetYYFromYear(const aYear: string): integer; overload;
begin
  // '2019' -> 19
  Result := Copy(aYear, Length(aYear) - 2, Length(aYear)).ToInteger;
end;

function GetYYFromYear(const aYear: integer): integer; overload;
begin
  // 2019 -> 19
  Result := aYear mod 100;
end;

 

Edited by Mike Torrettinni
typo
  • Like 1

Share this post


Link to post
43 minutes ago, Mike Torrettinni said:

Result := FormatDateTime('yy', aDate).ToInteger;

YearOf(aDate) mod 100

  • Like 4

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×