Delphi : Parse or Explode a string based on a parameter field

this is a small code that i put together to convert the date time format of “2017-11-18 08:25” to the date time format that i am using right now which is “11/18/2017 8:25:00 AM”.  For now i will make due with this one and so far it works.

enjoy,

coffee cup

 

 

var
vDATE : TDateTime;
vPOS : Integer;
vList : TStrings;
begin
//convert from 2017-11-18 08:25
//convert to 11/18/2017 8:25:00 AM

vPOS := POS(‘ ‘, edtDATE_ORIG.Text);

edtDATE_CHOP.Text := Trim(Copy(edtDATE_ORIG.Text,1, vPOS));
edtTIME_CHOP.Text := Trim(Copy(edtDATE_ORIG.Text,vPOS + 1, 100));

vList := TStringList.Create;
try
ExtractStrings([‘-‘], [], PChar(edtDATE_CHOP.Text), vList);

edtYEAR.Text := vList.Strings[0];
edtMONTH.Text := vList.Strings[1];
edtDAY.Text := vList.Strings[2];

//year, month, day
edtDATE_CURR.Text := edtMONTH.Text + ‘/’ + edtDAY.Text + ‘/’ + edtYEAR.Text;
vDATE := StrToDateTime(edtDATE_CURR.Text + ‘ ‘ + edtTIME_CHOP.Text);
edtDATETIME.Text := DateTimeToStr(vDATE);

finally
vList.Free;
end;

Leave a Reply

Your email address will not be published. Required fields are marked *