Home > Enterprise >  How can I convert an XML date to a valid datetime?
How can I convert an XML date to a valid datetime?

Time:09-17

My program reads an XML file and extracts any date it can find. After a date was found, it uploads it to a database, but I can't figure out how I could convert an XML string (date) into a valid SQL datetime.

My XML date format:

2021-08-26T00:25:26.737185Z

CodePudding user response:

The date looks like it is a date in ISO 8601 format. In newer versions of Delphi, there is a function called ISO8601ToDate in System.DateUtils that converts a string in that format to a DateTime value:

USES System.DateUtils;
.
.
VAR S : STRING;
VAR DT : TDateTime;
.
.
S:='2021-08-26T00:25:26.737185Z';
DT:=ISO8601ToDate(S);
.
.
  • Related