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.

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

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.

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

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 which is next day GTM+2.5.

Reference:  Pinal Dave (https://blog.sqlauthority.com)

Joes 2 Pros, SQL Scripts
Previous Post
SQLAuthority News – Pluralsight Giving Away Free Subscription to Quiz Participants
Next Post
SQL SERVER – Tips from the SQL Joes 2 Pros Development Series – Sparse Data and Space Used by Sparse Data – Day 17 of 35

Related Posts

100 Comments. Leave new

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

    1. GETDATE( )
    2. SYSDATETIME( )

    Reply
  • 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

    Reply
  • shatrughna kumar
    August 16, 2011 7:21 am

    Correct option is #1.
    New Delhi
    India

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

    Reply
  • Uday Bhoopalam
    August 16, 2011 7:41 am

    GETDATE() is the correct answer

    Uday Bhoopalam

    Reply
  • Uday Bhoopalam
    August 16, 2011 7:55 am

    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

    Reply
  • Rene Alberto Castro Velasquez
    August 16, 2011 8:12 am

    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

    Reply
  • 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

    Reply
  • 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

    Reply
  • Aditya Bisoi (@AdityaBisoi07)
    August 16, 2011 8:55 am

    Question 16

    Ans : 1- GETDATE( )

    Chennai, INDIA

    Reply
  • Correct answer is GETDATE() (option #1) that will return current date with millisecond precision

    I am from USA

    Reply
  • Rajneesh Verma
    August 16, 2011 9:06 am

    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)

    Reply
  • option 1

    Reply
  • GETDATE() will returns seconds expressed in Millisecond. and
    GETUTCDATE() will show in UTC format..
    Both are correct.

    Arjun
    INDIA

    Reply
  • GETDATE( ) is the correct answer

    Scalable – Systems

    Reply
  • Option 1- GETDATE( ) is correct

    Noida, INDIA

    Thanks,
    Rahul Sharma

    Reply
  • The correct answer is option 1 and 2 that is
    1. GETDATE( )
    2. SYSDATETIME( )

    Mahmad Khoja
    INDIA
    AHMEDABAD

    Reply
  • Correct option is 1

    GetDate()
    This will return the result in milliseconds

    INDIA

    Reply
  • 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

    Reply
  • Correct Answer is Option 1. GETDATE( )

    Pratik Raval
    India

    Reply

Leave a Reply