DateTime value in SQL vs Delphi offset by 2 ?

153 views
Skip to first unread message

Leapin

unread,
Jun 6, 2003, 1:07:05 PM6/6/03
to
I have a datetime field called StartTime in SQL 7.0 defualt value = 0
This is 1/1/1900 12:00:00 AM

If I display this value under Query Analyzer like:
Convert(float, StartTime) = 0.0

In delphi I display as
FloatToStr(qryRunStartTime.value) = 2.0

Why is this ????
This is causing me problems elsewhere when I do comparisons.
Why is it different by 2.0 ?


Alain Quesnel

unread,
Jun 6, 2003, 2:46:33 PM6/6/03
to
What version of Delphi are you using?

--

Alain Quesnel
alains...@logiquel.com

www.logiquel.com


"Leapin" <wa...@resa.net> wrote in message
news:3ee0...@newsgroups.borland.com...

Leapin

unread,
Jun 6, 2003, 4:21:15 PM6/6/03
to
Delphi 6 Ent, ADO, IP3000
"Alain Quesnel" <alains...@logiquel.com> wrote in message
news:3ee0e215$1...@newsgroups.borland.com...

Wayne Niddery [TeamB]

unread,
Jun 6, 2003, 5:05:26 PM6/6/03
to
Leapin wrote:
> I have a datetime field called StartTime in SQL 7.0 defualt value = 0
> This is 1/1/1900 12:00:00 AM
>
> In delphi I display as
> FloatToStr(qryRunStartTime.value) = 2.0
>
> Why is it different by 2.0 ?

The Delphi TDateTime interprets 0 as Dec 30, 1899 (there's your two days).
This was done to match COM apparently (and MS erred in COM, it would've made
more sense to make it the *last* day of the year instead of the second
last).

However, if this is a date field in SQL Server, and you retrieve it as a
DateTime field, then this should be transparent to you. Why are you treating
it as a float?

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
Powered by Delphi and IB: http://www.logicfundamentals.com/RadBooks.html
"Democracy, without that guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman


Leapin

unread,
Jun 10, 2003, 3:50:54 PM6/10/03
to
I have a routine that adds up seconds in a longint field and then converts
to a dateTime.

I am adding 2 to the days to make equivalent.
I guess I should maybe have used the FloatToDateTime function ?


"Wayne Niddery [TeamB]" <wnid...@chaff.aci.on.ca> wrote in message
news:3ee10278$1...@newsgroups.borland.com...

Wayne Niddery [TeamB]

unread,
Jun 10, 2003, 11:31:18 PM6/10/03
to
Leapin wrote:
> I have a routine that adds up seconds in a longint field and then
> converts to a dateTime.

Get the field AsDateTime from the database and use DecodeTime to get
seconds.

Reply all
Reply to author
Forward
0 new messages