Specifically I want to emulate the functionality of the
CDate() function in VB.
Suggestions?
Dan
> I'm looking for a function that will return TDateTime for
> a generic date expression.
The closest thing available in the native VCL is StrToDate().
Gambit
There is no generic solution to this problem since some dates in string
format are simply ambiguous if you do not know the format used up front.
The VarToDatetime function from the Variants unit can deal with a lot
more formats than StrToDate, it falls back on the conversion function
from the OLE API, which is part of Windows.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Peter referred me to VarToDateTime, which appears to be the
same wrapper that VB's CDate uses.
Thanks for the response.
Dan
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:4865da2d$1...@newsgroups.borland.com...
I agree that generic solutions aren't all that reliable, but
they at least give you a shot at it<g>. Using mixed
alpha/numeric can help remove ambiguity from data formats
though.
11/12/2008 - Nov 12 or Dec 11?
11DEC2008 or 11 DEC 2008, unambiguous...
We expose the function via our own scripting for users so I
am happy to find it instead of having to build it myself<g>.
It allows users to more easily avoid the ambiguitiy when
system data format settings might not be easily available to
them.
Dan
"Peter Below (TeamB)" <no...@nomail.please> wrote in message
news:xn0fryrc...@newsgroups.borland.com...
I do not know about the date formats actually supported by CDate(), as none are
listed on this MS reference page:
http://msdn.microsoft.com/en-us/library/2dt118h2(VS.85).aspx
But I have a Delphi a "String To Time" converter implementation ready which very
closely follows the "GNU Date Input Formats" as specified here:
http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html
It analyses a string for date / time information similar to StrToDate(), except
that it accepts a much greater variety of input formats and has an extended
return value which also includes DST and / or time offsets.
The implementation compiles directly into your executable, it does NOT require
external files. Since I mostly developed it for WikiTaxi offline reader
(available from my web-site), it is not (yet) available as a separate Delphi
component. However, if you contact me via personal e-mail I am sure we can work
something out.
Ralf
---
The Delphi Inspiration
http://www.yunqa.de/delphi/
Correct, the CDate() functionality is poorly documented
except to say "it mostly works for a lot of stuff".
It looks like the function you describe would be useful, but
the VarToDatetime function does what I need for now. As
best I can tell, that function and CDate probably wrap the
same OLE API function.
A function like you describe would fit nicely into the
Codegear runtime. Having acutal documentation using date
format specifications is a pretty radical idea though <g>.
Dan
"Ralf Junker - http://www.yunqa.de/delphi/"
<del...@yunqa.dot.de> wrote in message
news:vche64haoon3g7cgn...@4ax.com...