Published Mar 18, 2019

Why Date-ing is Hard

    Dive into the complexities of date handling and time representation as the episode unravels the challenges faced by developers with standards like ISO 8601, explores SQL Server's datetime precision, and offers insights into tech conference engagement and consumption.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • Precision

      Understanding datetime precision in SQL Server is crucial for developers. Alan Underwood explains that the datetime2 data type offers precision down to seven decimal places, allowing for accurate representation of dates from the year 1 to 9999 1. This precision is essential for applications requiring exact time measurements. However, Underwood warns that the standard datetime type rounds to the nearest three-thousandths of a second, which can lead to unexpected results 2.

      Your precision is probably not what you thought it was. Right. And if you need to store things down to the nanosecond, a date time specific type will not get you the accuracy you need.

      --- Alan Underwood

      Choosing the right datetime type can save storage space and ensure the necessary precision for your application.

         

      Function Choice

      The choice between GetDate and SYSDATETIME functions in SQL Server can significantly impact precision. Michael Outlaw suggests replacing the GetDate function with SYSDATETIME for better precision, as it provides nanosecond accuracy 3. This change is particularly beneficial for applications requiring precise time tracking. Alan Underwood also highlights the importance of understanding the nuances of different SQL systems, as each may have unique behaviors and precision levels 3.

      Throw get date out the window. Throw get UTC date out the window and use these sysdate functions.

      --- Alan Underwood

      Adopting SYSDATETIME can enhance the accuracy and reliability of time data in SQL Server.

         

      Offsets

      Storing offsets and time zone information in SQL Server is vital for accurate time representation. Alan Underwood explains that while you can derive an offset from a time zone, the reverse is not possible, making it crucial to store offsets when precision is needed 4. This distinction is important for applications operating across multiple time zones. Joe Zack emphasizes the need to anticipate future requirements for time zone data, as failing to store it initially can lead to complications later 4.

      You might not know you need it until you're not going to know you need it until you know that you need it, and that might be too late to find out that you need it.

      --- Joe Zack

      Ensuring that offsets are stored can prevent future issues and maintain the integrity of time data.

    Related Episodes