SQL SERVER – Tips from the SQL Joes 2 Pros Development Series – System and Time Data Types – Day 16 of 35

Answer simple quiz at the end of the blog post and -
Every day one winner from India will get Joes 2 Pros Volume 3.
Every day one winner from United States will get Joes 2 Pros Volume 3.

System and Time Data Types

Keeping track of date and time data points has always been a critical part of online transactional databases. For example, each sales invoice record needs a date-time stamp, as do systems which track quotes and customer contacts regarding sales opportunities.

Think of how many times during your workday that you rely on a date-time stamp as helpful metadata to sort or locate the latest information in a report or data source. Global organizations, in particular, have a need for their in-house communication, reporting, and collaboration tools to appropriately convey accurate date and time information in order to keep every part of the organization in sync.

Recap of DateTime Functions

GETDATE( ) and SELECT SYSDATETIME( ) both return the current date and time in your time zone. However, GETDATE( ) shows fractional seconds expressed in milliseconds (.333 second), and SYSDATETIME( ) shows fractional seconds expressed in nanoseconds (.3333333 second). SYSDATETIME( ) return similar results but their precisions differ.

What time is it right now in the UK? UTC is Coordinated Universal Time, formerly known as Greenwich Mean Time (GMT). (UTC is also known by the terms zulu time, world time, and universal time.)

SELECT GETUTCDATE( ) will show the current time expressed in terms of UTC. GETUTCDATE( ) is less precise than SYSUTCDATETIME ( ). However there is a UTC function that gets down to the nanoseconds, SYSUTCDATETIME( ). When we run all 4 of these functions together We see the two top times in my local time zone (in my case the Pacific time zone) and the two bottom times in UTC.

Question 16

Which one of the following functions will return the date and time in the current time zone to a precision of milliseconds?

  1. GETDATE( )
  2. SYSDATETIME( )
  3. GETUTCDATE( )
  4. SYSUTCDATETIME( )

Rules:

Please leave your answer in comment section below with correct option, explanation and your country of resident.
Every day one winner will be announced from United States.
Every day one winner will be announced from India.
A valid answer must contain country of residence of answerer.
Please check my facebook page for winners name and correct answer.
Winner from United States will get Joes 2 Pros Volume 3.
Winner from India will get Joes 2 Pros Volume 3.
The contest is open till next blog post shows up at http://blog.sqlauthority.com which is next day GTM+2.5.

Reference:  Pinal Dave (http://blog.SQLAuthority.com)

About these ads

104 thoughts on “SQL SERVER – Tips from the SQL Joes 2 Pros Development Series – System and Time Data Types – Day 16 of 35

  1. The following functions will return the date and time in the current time zone to a precision of milliseconds:

    1. GETDATE( )
    2. SYSDATETIME( )

    Like

  2. Forgot to mention location….

    The following functions will return the date and time in the current time zone to a precision of milliseconds:

    1. GETDATE( )
    2. SYSDATETIME( )

    Option 3 and 4 are wrong answers because they will return the time in UTC format.

    Thanks,
    Kamlesh
    Bangalore, India

    Like

  3. Correct answer is Option #1

    1.GETDATE()

    becuase option #1 GETDATE() and #2 SYSDATETIME() returns date and time value with respect to CURRENT time zone, however, option #1 returns in fractional seconds expressed in milliseconds,
    option #2 returns in fractional seconds expressed in nanoseconds.

    Option #3 GETUTCDATE() and #4 SYSUTCDATETIME() returns the date and time value in UTC format., so these are incorrect.

    Thanks.

    Country – India.

    Like

  4. Getdate() is the correct answer it returns the date and time in our zone and the time with a milli seconds – 3position

    Uday Bhoopalam
    USA

    Like

  5. Correct answer is No. 1 because GETDATE( ) return the date and time in the current time zone to a precision of milliseconds. Option No. 2 does the same but with a precision of nanoseconds, so is incorrect. Option 3 and 4 are incorrect beccause they return the date and time expressed in terms of UTC.
    Rene Castro
    El Salvador

    Like

  6. Answer is GETDATE( )

    For DataTime in current time zone we have these :
    GETDATE( ) shows fractional seconds expressed in milliseconds (.333 second),
    SYSDATETIME( ) shows fractional seconds expressed in nanoseconds

    Aditi S
    USA

    Like

  7. 1) GETDATE( )

    Option 1) is correct because the precision is to a milliseconds
    Option 2) gives the system time with more frational second precision
    Other 2 funtions just show the UTC times.

    Leo Pius
    USA

    Like

  8. As in description “However, GETDATE( ) shows fractional seconds expressed in milliseconds (.333 second), and SYSDATETIME( ) shows fractional seconds expressed in nanoseconds (.3333333 second).” So its very clear that GETDATE( ) will return seconds expressed in Millisecond.

    Option 1 is the right.

    Thanks…
    Rajneesh Verma
    (INDIA)

    Like

  9. The answer is Getdate() since it displays the current time zone’s date and time to the milliseconds grain.

    Option 1 : It gives the current time zone’s date and time to the precision of milliseconds.
    Option 2 : It gives the current time zone’s date and time to the precision of 100 nano seconds.
    Option 3 : It gives the UTC date and time to the precision of milliseconds.
    Option 4 : It gives the UTC date and time to the precision of 100 nano seconds.

    Shikha Gupta
    USA

    Like

  10. Pingback: SQL SERVER – Win a Book a Day – Contest Rules – Day 0 of 35 Journey to SQLAuthority

  11. Correct answer is # 1.

    It displays the current time zone’s date and time with respect to the milliseconds format.

    Option 1 GETDATE(): It returns the current date and time in your time zone. It shows fractional seconds expressed in milliseconds (.333 second).
    Option 2 SYSDATETIME(): It returns the current date and time in your time zone. But it shows fractional seconds expressed in nanoseconds (.3333333 second).
    Option 3 GETUTCDATE(): It will show the current time expressed in terms of UTC. GETUTCDATE( ) is less precise than SYSUTCDATETIME ( ).
    Option 4 SYSUTCDATETIME(): It will show the current time expressed in terms of UTC and it gets down to the nanoseconds.

    Gopalakrishnan Arthanarisamy
    Unisys, Bangalore, India

    Like

  12. Correct answer is # 1.

    It displays the current time zone’s date and time with respect to the milliseconds format.

    Option 1 GETDATE(): It returns the current date and time in your time zone. It shows fractional seconds expressed in milliseconds (.333 second).

    Option 2 SYSDATETIME(): It returns the current date and time in your time zone. But it shows fractional seconds expressed in nanoseconds (.3333333 second).

    Option 3 GETUTCDATE(): It will show the current time expressed in terms of UTC. GETUTCDATE( ) is less precise than SYSUTCDATETIME ( ).

    Option 4 SYSUTCDATETIME(): It will show the current time expressed in terms of UTC and it gets down to the nanoseconds.

    Gopalakrishnan Arthanarisamy
    Unisys, Bangalore, India

    Like

  13. Correct answer is Option #1

    1.GETDATE()

    becuase option #1 GETDATE() and #2 SYSDATETIME() returns date and time value with respect to CURRENT time zone, however, option #1 returns in fractional seconds expressed in milliseconds,
    option #2 returns in fractional seconds expressed in nanoseconds.

    Option #3 GETUTCDATE() and #4 SYSUTCDATETIME() returns the date and time value in UTC format., so these are incorrect.

    Like

  14. Correct answer is Option #1

    1.GETDATE()

    becuase option #1 GETDATE() and #2 SYSDATETIME() returns date and time value with respect to CURRENT time zone, however, option #1 returns in fractional seconds expressed in milliseconds,
    option #2 returns in fractional seconds expressed in nanoseconds.

    Option #3 GETUTCDATE() and #4 SYSUTCDATETIME() returns the date and time value in UTC format., so these are incorrect.

    Cochin,INDIA

    Like

  15. Correct option is Option #1
    GETDATE( )

    SYSDATETIME() returns current time zone datetime upto nanoseconds which is not required.

    Option #3 GETUTCDATE() and #4 SYSUTCDATETIME() return datetime in UTC format which is also not required.

    Sumit
    India

    Like

  16. Answer is 1;
    SELECT GETDATE( )

    GETDATE( ) shows fractional seconds expressed in milliseconds ,
    and SYSDATETIME( ) shows fractional seconds expressed in nanoseconds

    GETUTCDATE( ) will show the current time expressed in terms of UTC. SYSUTCDATETIME ( ) will show curretnt time gets down to the nanoseconds.

    Like

  17. Option 1 is correct. Because

    1) GETDATE() returns a DATETIME value. A DATETIME value has precision upto 3 milliseconds.

    2) SYSDATETIME() returns a DATETIME2 value. which gives precision upto 100nanoseconds

    Thanks
    Santosh.S
    Bangalore

    Like

  18. Answer 1 is Correct

    because GETDATE( ) gives fractional seconds expressed in milliseconds
    and GETUTCDATE( ) will show the current time expressed in milliseconds terms of UTC

    Abhishek MIshra
    INDIA NOIDA

    Like

  19. Hi Sir,

    Option 1 is the correct answer as GETDATE() will return the date and time in the current time zone to a precision of milliseconds (.333 second).

    option 2 SYSDATETIME() will return the date and time in the current time zone to a precision of nanoseconds (.3333333 second).

    Option 3 GETUTCDATE() will show the current time expressed in terms of UTC to a precision of milliseconds.

    Option 4 SYSUTCDATETIME() will show the current time expressed in terms of UTC to a precision of nanoseconds.

    So the correct answer is Option no 1 GETDATE().

    P.Anish Shenoy,
    INDIA, Bangalore, Karnataka

    Like

  20. hello,
    correct answer is option #1 i.e: getdate()

    getdate(): it will return the date and time in the current time zone to a precision of milliseconds
    sysdatetime(): nano seconds

    azaad mohammed
    from mumbai,india

    Like

  21. Hi Pinal,

    The answer for the above question is Option 1) GETDATE( ).

    Explanation:

    Asked : Function will return the date and time in the current time zone to a precision of milliseconds.

    Explanation : Here we need to find out Current time zone in the above article it is very beautifully explained by pinal sir that GETDATE() will return current date and time in your time zone by default your time zine is said as default time zone though GETUTCDATE( ) returns the same in milliseconds but here our requirement is current time zone, i.e our zone.

    Apart from that no other option will give us that result.

    Diljeet kumari

    Country : India

    Like

  22. Correct Answer:
    1. GETDATE()

    GETDATE() will return current date and time in current time zone with precision of milliseconds.

    Hiren Bavishi
    India

    Like

  23. Correct Answer is Option 1

    Explanation: Option 3 and 4 provide date and time in Universal Time Coordinates (UTC) and option 2 provide date and time in current time zone but with precision of nanoseconds.
    Option 1 provide date and time in current time zone to a precision of milliseconds.

    Country – INDIA (Gujarat)

    Like

  24. Correct Answer is option No : 1 ) GETDATE( )

    GETDATE( ) returns current time zone details with milliseconds precision.

    Shekhar Gurav
    Country : INDIA

    Like

  25. The correct answer is option 1 :
    1. GETDATE( )
    It shows fractional seconds expressed in milliseconds.

    Deepali Bhende.
    Country : INDIA

    Like

  26. Correct Answer is #1

    GetDate( )

    The 2nd and 4th ones return time to nanoseconds not milliseconds and the 3rd and 4th return Greenwich time not my local time.

    USA

    Like

  27. Hi Pinal,

    Challenge:
    Question 16
    Which one of the following functions will return the date and time in the current time zone to a precision of milliseconds?
    1. GETDATE( )
    2. SYSDATETIME( )
    3. GETUTCDATE( )
    4. SYSUTCDATETIME( )

    Correct Answer:
    1. GETDATE( )

    Explanation:
    GetDate( ) will show return the current date and time in milliseconds. SysDateTime( ) will return the current date and time in nanoseconds. GetUTCDate( ) will return the Coordinated Universal Time in milliseconds.
    SysUTCDateTime( ) will return the Coordinated Universal Time in nanoseconds.

    Country:
    United States

    Thanks for the knowledge!

    Regards,

    Bill Pepping

    Like

  28. Correct Answer is: 1

    Explanation:
    Option 3 and 4 returns the UTC Date and Time, so they are not the correct options for this question. And Option 2 returns the date and time in local time zone but precision is in nanoseconds. So the correct answer is the option 1.

    Thanks,
    Basavaraj

    Like

    • Correct Answer is: 1

      Explanation:
      Option 3 and 4 returns the UTC Date and Time, so they are not the correct options for this question. And Option 2 returns the date and time in local time zone but precision is in nanoseconds. So the correct answer is the option 1.

      Thanks,
      Basavaraj
      India

      Like

  29. Which one of the following functions will return the date and time in the current time zone to a precision of milliseconds?

    GETDATE( )
    SYSDATETIME( )
    GETUTCDATE( )
    SYSUTCDATETIME( )

    Solution:

    The right answer is Getdate().This function returns the current time zone or local date and time to the precision of milliseconds .

    1 -> This function returns the current time zone date and time to the precision of milliseconds.
    2 -> This function returns the current time zone date and time to the precision of 100 nano seconds or 10-7 seconds.
    3 -> This function returns the Coordinated Universal Time (UTC) date and time to the precision of milliseconds.
    4 -> This function returns the Coordinated Universal Time (UTC) date and time to the precision of 100 nano seconds or 10-7 seconds.

    Nagaraj Ejanthkar
    USA

    Like

  30. The answer is Option 1
    getdate() , because show the time in milliseconds and my time zone.

    SYSDATETIME( ) is not correct because, we need the time in milliseconds not in nanosecond – wrong answer

    GETUTCDATE( ) In spite the time is in millisecond, is not local time, is a Universal Time – wrong answer
    SYSUTCDATETIME( ) its UTC time in nanosecond, not local time – Wrong answer

    Leonardo

    Country: Chile

    Like

  31. Answer: 1. GetDate() gives the date and time with millisecond precision. It returns the current date and time in YYYY-MM-DD HH:MM:SSS.MMM where MMM is the millisecond portion.

    Damodaran Venkatesan
    USA

    Like

  32. Hi Pinal Dave,

    GetDate() is the function that will return the date and time in the current time zone expressed in milliseconds.

    The answer is #1.

    David, USA

    Like

  33. The answer for Question 16 is Option 1) GETDATE( ).

    Why Explanation:

    We need a Function which will return the date and time in the current time zone to a precision of milliseconds as we have seen that your time zone by is nothing but default time zone.

    But GETUTCDATE( ) returns the time in milliseconds but here we need is current time zone or our zone.

    Hence the correct Option is Option 1 .

    Why Other Answers are wrong:

    Option 2) SYSDATETIME( ) will return the time in nanoseconds but we need time in millisconds so invalid answer.

    Option 3) GETUTCDATE( ) and Option 4) SYSUTCDATETIME( ) will return UTC time which is not required hence ruled out.

    DILIP KUMAR JENA
    Country : INDIA

    Like

  34. Which one of the following functions will return the date and time in the current time zone to a precision of milliseconds?

    1. GETDATE()

    Like

  35. Hi Pinal,
    The correct answer is option 1 GETDATE()

    Ques:-Which option of the following functions will return the date and time in the current time zone to a precision of milliseconds?

    Explanation:- As GETDATE( ) returns current date and time where in the time is having hour,minutes and fractional seconds expressed in milliseconds.

    Thanks,
    Manik Dey
    India

    Like

  36. Pingback: SQL SERVER – SSQL Architecture Basics – Core Architecture Concepts – Book Available for SQL Server Certification Journey to SQLAuthority

  37. I think the correct answer is both No. 1 because GETDATE( ) return the date and time in the current time zone to a precision of milliseconds and No. 2 becauseSysDateTime does the same thing but with higher precision. Both are accurate to the millisecond.

    Like

  38. Pingback: SQL SERVER – Clustered Index and Primary Key – Contest Win Joes 2 Pros Combo (USD 198) – Day 3 of 5 « SQL Server Journey with SQL Authority

  39. Pingback: SQL SERVER – Weekly Series – Memory Lane – #042 | Journey to SQL Authority with Pinal Dave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s