Showing posts with label compute. Show all posts
Showing posts with label compute. Show all posts

Sunday, February 19, 2012

DATEDIFF Weirdness!

Does not compute!!
Can someone explain why DATEDIFF function adds 3 hours to the result?!
I constantly had false results and I then noticed that the time values
are incorrect. Then I made this query to check it:
select DATEDIFF(second, 'jan 1 1970', '2003-08-14')
It returns: 1060819200
Then I made a nice perl script to prove my point:
#!c:\perl\bin\perl.exe -w
print "TIME IS: " . localtime(1060819200);
Result is: Thu Aug 14 03:00:00 2003 (!?)
My Server and Client-machines are both set to same time zone, same date,
same time... So where does this extra 3 hours come from? Does it have
sth to do with UTC-time as GETUTCDATE() returns a time that is 3 hours
behind the time of my machines (Finnish time...).
But anyway, how can I get the DATEDIFF-function to work properly. I
really don't need the extra 3 hours... ;)
Oh, BTW... it's SQL Server 2000 I'm talking about and Windows 2000
Server (SQL Server) & Professional (SQL Server client).
-N-The problem is not with SQL Server it is with the way you are calling
localtime.
This function converts the value returned by time to a nine-element list
with the time corrected for the local time zone.
http://www.ib-perl.org/class/localtime.html
"Niko" <niko.ratto@.noSPAMkia.fi> wrote in message
news:TcN_a.9951$g4.193781@.news1.nokia.com...
> Does not compute!!
> Can someone explain why DATEDIFF function adds 3 hours to the result?!
> I constantly had false results and I then noticed that the time values
> are incorrect. Then I made this query to check it:
> select DATEDIFF(second, 'jan 1 1970', '2003-08-14')
> It returns: 1060819200
> Then I made a nice perl script to prove my point:
> #!c:\perl\bin\perl.exe -w
> print "TIME IS: " . localtime(1060819200);
> Result is: Thu Aug 14 03:00:00 2003 (!?)
>
> My Server and Client-machines are both set to same time zone, same date,
> same time... So where does this extra 3 hours come from? Does it have
> sth to do with UTC-time as GETUTCDATE() returns a time that is 3 hours
> behind the time of my machines (Finnish time...).
> But anyway, how can I get the DATEDIFF-function to work properly. I
> really don't need the extra 3 hours... ;)
> Oh, BTW... it's SQL Server 2000 I'm talking about and Windows 2000
> Server (SQL Server) & Professional (SQL Server client).
> -N-
>