TDateTime is a double, @lucamar first parse the string, then converts the string to double.
EncodeDateTime directly creates a double. Now please tell me wich method reinvents the wheel.
Exactly.
PS: Don't get me wrong, @lucamar's method it's a perfectly good one, use it if you like it, but saying that is better then EncodeDatetime is a slight exaggeration.
Of course, Lucamar's post has its place, as it is nice to show that there is this way, for completeness.
However, including unnecessary string parsing can hardly be called a better solution.
Please, notice the context: the OP is already using
StrToDateTime, presumably because he's getting the date/time (whether as a constant ot from elsewhere) as a string, and the question arised about the different default formats it may use to parse the string, which he would have to do anyway to use
EncodeDateTime()Since he's already using it and any other method implies parsing the string anyway, isn't it better (and IMHO the "correct" way) to use the correct overload of
StrToDateTime?
It would, of course, be otherwise if he got the date(s) as separate integers: Then the better solution would in fact be
EncodeDateTime. But that was not the question.