Why Date-ing is Hard

Topics covered
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


Why Domain Driven Design
Answers 383 questions
Tackling Tough Developer Questions
Answers 383 questionsHow to be a Programmer
Answers 383 questionsHow to be an Advanced Programmer
Answers 383 questionsUnderstanding Complexity Theory
Answers 383 questions86. Lightning Talks
Answers 383 questionsClean Code - Formatting Matters
Answers 383 questions
What is Algorithmic Complexity?
Answers 383 questionsStackOverflow AI Disagreements, Kotlin Coroutines and More
Answers 383 questions

Technical Challenges of Scale at Twitter
Answers 383 questionsThere is still cool stuff on the internet
Answers 383 questionsDesigning Data-Intensive Applications – Scalability
Answers 383 questions88. Algorithmic Complexity
Answers 383 questionsCaching Overview and Hardware
Answers 383 questionsClean Code - How to Write Amazing Functions
Answers 383 questions
