abdellahmehdi 0 Posted June 3, 2022 How do I get the last two digits of a date ( 22) ? 2022 => 22 Share this post Link to post
corneliusdavid 220 Posted June 3, 2022 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) 1 Share this post Link to post
Mike Torrettinni 198 Posted June 3, 2022 (edited) 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 June 3, 2022 by Mike Torrettinni typo 1 Share this post Link to post
Fr0sT.Brutal 900 Posted June 3, 2022 43 minutes ago, Mike Torrettinni said: Result := FormatDateTime('yy', aDate).ToInteger; YearOf(aDate) mod 100 4 Share this post Link to post
Mike Torrettinni 198 Posted June 3, 2022 31 minutes ago, Fr0sT.Brutal said: YearOf(aDate) mod 100 Nice, thanks! 1 Share this post Link to post