Exemplo : InverteStringData('2017-05-12','AAAA-MM-DD','DD/MM/AAAA','/');
Retorno : 12/05/2017
}
function InverteStringData(sData, sFormatoOrigem,sFormatoDestino,simbolo: String): String;
var
sDia : String;
sMes : String;
sAno : String;
begin
if (sFormatoOrigem = 'DD/MM/AAAA') or (sFormatoOrigem = 'DD-MM-AAAA') then
begin
sDia := Copy(sData,1,2);
sMes := Copy(sData,4,2);
sAno := Copy(sData,7,4);
end
else
if (sFormatoOrigem = 'MM/DD/AAAA') or (sFormatoOrigem = 'MM-DD-AAAA') then
begin
sMes := Copy(sData,1,2);
sDia := Copy(sData,4,2);
sAno := Copy(sData,7,4);
end
else
if (sFormatoOrigem = 'AAAA/MM/DD') or (sFormatoOrigem = 'AAAA-MM-DD') then
begin
sAno := Copy(sData,1,4);
sMes := Copy(sData,6,2);
sDia := Copy(sData,9,2);
end
else
begin
Result := DateToStr(Date);
Exit;
end;
if (sFormatoDestino = 'DD/MM/AAAA') or (sFormatoDestino = 'DD-MM-AAAA') then
begin
Result := sDia + simbolo + sMes + simbolo + sAno;
end
else
if (sFormatoDestino = 'MM/DD/AAAA') or (sFormatoDestino = 'MM-DD-AAAA') then
begin
Result := sMes + simbolo + sDia + simbolo + sAno;
end
else
if (sFormatoDestino = 'AAAA/MM/DD') or (sFormatoDestino = 'AAAA-MM-DD') then
Result := sAno + simbolo + sMes + simbolo+ sDia
else
begin
Result := DateToStr(Date); // Retorna data do sistema
Exit;
end;
end;
var
sDia : String;
sMes : String;
sAno : String;
begin
if (sFormatoOrigem = 'DD/MM/AAAA') or (sFormatoOrigem = 'DD-MM-AAAA') then
begin
sDia := Copy(sData,1,2);
sMes := Copy(sData,4,2);
sAno := Copy(sData,7,4);
end
else
if (sFormatoOrigem = 'MM/DD/AAAA') or (sFormatoOrigem = 'MM-DD-AAAA') then
begin
sMes := Copy(sData,1,2);
sDia := Copy(sData,4,2);
sAno := Copy(sData,7,4);
end
else
if (sFormatoOrigem = 'AAAA/MM/DD') or (sFormatoOrigem = 'AAAA-MM-DD') then
begin
sAno := Copy(sData,1,4);
sMes := Copy(sData,6,2);
sDia := Copy(sData,9,2);
end
else
begin
Result := DateToStr(Date);
Exit;
end;
if (sFormatoDestino = 'DD/MM/AAAA') or (sFormatoDestino = 'DD-MM-AAAA') then
begin
Result := sDia + simbolo + sMes + simbolo + sAno;
end
else
if (sFormatoDestino = 'MM/DD/AAAA') or (sFormatoDestino = 'MM-DD-AAAA') then
begin
Result := sMes + simbolo + sDia + simbolo + sAno;
end
else
if (sFormatoDestino = 'AAAA/MM/DD') or (sFormatoDestino = 'AAAA-MM-DD') then
Result := sAno + simbolo + sMes + simbolo+ sDia
else
begin
Result := DateToStr(Date); // Retorna data do sistema
Exit;
end;
end;
Sem comentários:
Enviar um comentário