Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Date Expression to TDateTime

5 views
Skip to first unread message

Dan Barclay

unread,
Jun 27, 2008, 6:28:36 PM6/27/08
to
I'm looking for a function that will return TDateTime for a
generic date expression. I see EncodeDate() and friends,
but according to the docs they only work with numeric dates.
I'm looking for something more generic that will also work
with a date like "7 DEC 1941".

Specifically I want to emulate the functionality of the
CDate() function in VB.

Suggestions?

Dan


Remy Lebeau (TeamB)

unread,
Jun 28, 2008, 2:29:07 AM6/28/08
to

"Dan Barclay" <D...@MVPs.org> wrote in message
news:48656993$1...@newsgroups.borland.com...

> 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


Peter Below (TeamB)

unread,
Jun 28, 2008, 4:46:16 AM6/28/08
to
Dan Barclay wrote:

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

Dan Barclay

unread,
Jun 28, 2008, 4:27:04 PM6/28/08
to
Thanks. I ran across StrToDate, but it didn't handle
anything but numeric formats

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...

Dan Barclay

unread,
Jun 28, 2008, 4:24:49 PM6/28/08
to
Thanks Peter. It looks like VarToDatetime may be what I'm
looking for.

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...

Ralf Junker - http://www.yunqa.de/delphi/

unread,
Jun 29, 2008, 4:39:10 AM6/29/08
to
"Dan Barclay" <D...@MVPs.org> wrote:

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/

Dan Barclay

unread,
Jun 29, 2008, 2:01:32 PM6/29/08
to
Thanks Ralf.

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...

0 new messages