Extract Expiration Line Digit

2

I have the following digitable line of a ticket, I need a function to extract the expiration date of it, and then use it in others.

  

Fingerprint: 74893.12004.21627.007186.37931.981056 1 59490000041480

I know that 5949 is the ticket expiration, but I can not convert to a Date. I mounted the following function but it did not work:

 
function ExtrairDataVencimento(const CodigoBarras: String): TDateTime;
begin
Result := StrToDate('07/10/1997') + StrToInt(Copy(CodigoBarras, 34, 4));
WriteLn(Result);
end;

Any suggestions?

    
asked by anonymous 27.05.2014 / 22:17

1 answer

4

See if that's what you're looking for:

 
const
CodigoDeBarras: string = '74893.12004.21627.007186.37931.981056 1 59490000041480';

function ExtrairDataVencimento(const CodigoBarras: String): TDateTime;
begin
Result := StrToDate('07/10/1997') + StrToInt(Copy(CodigoBarras, 41, 4)); // 5949
ShowMessage(DateToStr(Result));
end;

If you are building a console application:

 
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils;

const
CodigoDeBarras: string = '74893.12004.21627.007186.37931.981056 1 59490000041480';

function ExtrairDataVencimento(const CodigoBarras: String): TDateTime;
begin
Result := StrToDate('07/10/1997') + StrToInt(Copy(CodigoBarras, 41, 4));
Writeln(DateToStr(Result));
end;

begin
ExtrairDataVencimento(CodigoDeBarras);
Readln;
end.

The DateToStr() function converts a value of type DataTime in a formatted string.

    
27.05.2014 / 22:22