-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInverteStringData.pas
More file actions
60 lines (60 loc) · 1.65 KB
/
InverteStringData.pas
File metadata and controls
60 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function InverteStringData(sData:String; sFormatoOrigem : String; sFormatoDestino: String):String;
//
// Recebe uma string de data, convertendo-a do formato ORIGEM para o formato
// DESTINO
//
// Ex:
// InverteStringData(DateToStr(Date),'DD/MM/AAAA','AAAA/MM/DD')
//
var
sDia : String;
sMes : String;
sAno : String;
begin
if 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' then
begin
sMes := Copy(sData,1,2);
sDia := Copy(sData,4,2);
sAno := Copy(sData,7,4);
end
else
if sFormatoOrigem = 'AAAA/MM/DD' then
begin
sAno := Copy(sData,1,4);
sMes := Copy(sData,6,2);
sDia := Copy(sData,9,2);
end
else
begin
MessageDlg('Formato original da data errado (Função InverteStringData) - A própria data do sistema foi retornada.',mtError,[mbOk],0);
Result := DateToStr(Date);
Exit;
end;
if sFormatoDestino = 'DD/MM/AAAA' then
begin
Result := sDia + '/' + sMes + '/' + sAno;
end
else
if sFormatoDestino = 'MM/DD/AAAA' then
begin
Result := sMes + '/' + sDia + '/' + sAno;
end
else
if sFormatoDestino = 'AAAA/MM/DD' then
begin
Result := sAno + '/' + sMes + '/' + sDia
end
else
begin
MessageDlg('Formato destino da data errado (Função InverteStringData) - A própria data do sistema foi retornada.', mtError,[mbOk],0);
Result := DateToStr(Date);
Exit;
end;
end;