MBox files, like Google Gmail export mailbox contains various types of data, among other things, the date of the mail message that interests me. The date of the message is in the format:
DayOfWeek, dd monthname yyyy hh:mm:ss +timezone
Mon, 03 Jun 2019 15:32:25 +0200
I was looking for some ready-made function in Delphi that I could translate a date string into TDateTime. If the whole string is impossible to parse to TDateTime, I can only try parse this part:
dd monthname yyyy hh:mm:ss
03 Jun 2019 15:32:25
but I admit that it is a bit of a hassle in my language to parse the month name. Could I ask for such a function if it exists? If such a ready-made function does not exist, I will make my own (or at least try).
Thank you in advance!
EDIT: SOLUTION
My guess is that this may not be useful to anyone, but if someone will have a similar problem, have a solution here. You can probably write it more elegantly, but it works.
// You can make your own formats here
const months : array[1..12,1..2] of string =
(('-01-',' Jan '),
('-02-',' Feb '),
('-03-',' Mar '),
('-04-',' Apr '),
('-05-',' May '),
('-06-',' Jun '),
('-07-',' Jul '),
('-08-',' Aug '),
('-09-',' Sep '),
('-10-',' Oct '),
('-11-',' Nov '),
('-12-',' Dec '));
function ChangeDateFormat(input: String): String;
var i: Integer;
begin
// day name and timezone is not needed, so we cut it
delete(input,1,Pos(',',input)+1);
delete(input,Pos('+',input)-1, Length(input));
for i := 1 to 12 do
input := StringReplace(input,
months[i,2],months[i,1],
[rfReplaceAll, rfIgnoreCase]);
result := Trim(input);
end;
For 'Date: Mon, 03 Jun 2019 15:32:25 +0200' mbox date string it looks like
WriteLn(ChangeDateFormat('Date: Mon, 03 Jun 2019 15:32:25 +0200'));
it gives back
03-06-2019 15:32:25
which is already recognized e.g. by Excel and allows sorting or other operations.
At the moment I haven't found any ready-made functions in Delphi.