November 17, 2009 at 7:05 am
Yeah, like what everyone else says - the question is misleading and both answers are actually right in different time zones. Can I have my points now please 😉
November 17, 2009 at 7:06 am
If the SELECT statements had been formulated to indicate the time zone (e.g., 2009-11-16 08:01:18.177 CST, 2009-11-16 14:01:18.177 GMT), then what you are saying would be correct. A person viewing the result sets could conclude they were the same time. However, the actual result set doesn't include any indication of the time zone, so a reasonable person would conclude that the results were two different times.
Sorry, the answer was just plain wrong leaving aside the fact that the question was phrased as a yes/no question and not as a true/false question.
Maybe the author meant that false meant "yes" and true meant "no".
November 17, 2009 at 7:11 am
cengland0 (11/17/2009)
Lynn, you have a valid point but if you were to show those times to a client, they would only see the output not the representation. So, for example, if someone wanted a report pulled that showed "clock in times" and I showed that time in UTC, they would freak out thinking the report is wrong and I would have to agree with them.
In a report, if I were to be displaying the date/time in UTC, I would be sure that the heading clearly stated that it was UTC. That comes down to presentation.
November 17, 2009 at 7:18 am
crussell-931424 (11/17/2009)
I got the following data:2009-11-16 07:05:34.010 Monday
2009-11-16 07:05:34.010 Monday
2009-11-16 14:05:34.017 Monday
2009-11-16 14:05:34.017 Monday
The seconds were different. So the answer is false. I want my score corrected.
Actually, the seconds are the same, the difference is in the milliseconds.
November 17, 2009 at 7:33 am
Lynn Pettis (11/17/2009)
david.wright-948385 (11/17/2009)
I think getdate() = getutcdate() would return false in your time zone, so I think they're probably different!Everyone is looking at the values, yes, they are "different", but both represent the same time. One is local, the other UTC.
This may be true Lynn but,
There is nothing inherent in the Datetime data type that references what time zone the data was generated in.
If I use datepart on the two values to get the hour, I get 8 and 14. Which are not the same Hour.
If I calculate DATEDIFF(hh,getdate(),getutcdate()) I'll get a value other than 0 as well.
Saying that they are the same because I can interpret one by looking at the code to be a UTC adjusted datetime does not make the two datetime results equivalent.
November 17, 2009 at 7:36 am
I answered false. I get different results.
November 17, 2009 at 7:38 am
Lynn Pettis (11/17/2009)
david.wright-948385 (11/17/2009)
I think getdate() = getutcdate() would return false in your time zone, so I think they're probably different!Everyone is looking at the values, yes, they are "different", but both represent the same time. One is local, the other UTC.
...so they're not the same 🙂 Stop digging!!
November 17, 2009 at 7:50 am
Ooh and I managed to get the query to return different seconds as well
(No column name)(No column name)
2009-11-16 08:45:49.000Monday
2009-11-16 08:45:49.000Monday
2009-11-16 14:45:48.997Monday
2009-11-16 14:45:48.997Monday
Although I'm a bit confused exactlyhow the later version that picks up the UTC datetime is earlier in seconds than the local datetime.
DECLARE @date1 datetime
DECLARE @date2 datetime
DECLARE @date3 datetime
DECLARE @date4 datetime
WHILE @date1 IS NULL OR (datepart(ss,@date1)-datepart(ss,@date4) = 0)
BEGIN
SELECT @date1=DATEADD(day, -1, GETDATE())
SELECT @date2=GETDATE() - 1
SELECT @date3=GETUTCDATE() - 1
SELECT @date4=DATEADD(day, -1, GETUTCDATE())
END
SELECT @date1,datename(dw,@date1)
SELECT @date2,datename(dw,@date2)
SELECT @date3,datename(dw,@date3)
SELECT @date4,datename(dw,@date4)
November 17, 2009 at 7:52 am
7:00 AM <> 2:00 PM, true
7:00 AM MST = 2:00 PM UTC, true.
That is the concept that the question is trying to address.
November 17, 2009 at 7:59 am
Lynn Pettis has explained in great detail the reason the times are the same, and as a matter of fact has explained the reasoning better than I could have. For which I thank Lynn.
Hopefully all who have been taking issue with what is, or is not the correct answer will have had their knowledge of date time functions expanded and will remember this.
Another point: To all who are taking issue with the questions wording. I challenge you to compose and submit a question of the day. Remembering that the QOD is meant not only to test knowledge of T-SQL, but to also teach.
Here is Steve Jones article about the QOD
http://www.sqlservercentral.com/articles/SQLServerCentral/62764/
And quoting from the article here is the objective of the QOD
The Question of the Day is just what it's titled: a daily question about some aspect of databases or SQL Server. It's designed to be a learning mechanism with a bit of fun and competition built into it.
November 17, 2009 at 8:01 am
crussell-931424 (11/17/2009)
I got the following data:2009-11-16 07:05:34.010 Monday
2009-11-16 07:05:34.010 Monday
2009-11-16 14:05:34.017 Monday
2009-11-16 14:05:34.017 Monday
The seconds were different. So the answer is false. I want my score corrected.
Did you run that in a batch?
November 17, 2009 at 8:02 am
I work with date time functions all of the time and would contend that since the Time Zone is not returned as part of the result, the times are different. My users would expect to see CST and GMT appended to the result in ored for them to discern what time refernce was being used. Without this, I would say the times returned are different.
November 17, 2009 at 8:09 am
Cliff Jones
My users would expect to see CST and GMT appended to the result
What you are discussing has been addressed by Lynn Pettis, you are referencing the mode of presentation, which is not what the question asked.
November 17, 2009 at 8:09 am
Lynn Pettis (11/17/2009)
7:00 AM <> 2:00 PM, true7:00 AM MST = 2:00 PM UTC, true.
That is the concept that the question is trying to address.
Maybe, but we are not "mind readers".
The question asked "Will all these statements when executed as a batch return the same date, hour, minute and second?"
Note the word "return". They do not return the same values.
This question is akin to the vague specifications that application designers/architects get from marketing, users, etc.
November 17, 2009 at 8:11 am
As a practicle matter, I would never win that argument with my clients.
Viewing 15 posts - 31 through 45 (of 203 total)
You must be logged in to reply to this topic. Login to reply