What are the differences between DATETIME, DATETIME2, and DATE, and when would you choose each one?
Short answer
DATE stores only a calendar date without any time component, DATETIME stores both a date and time but with a fixed precision and a limited date range going back to the year 1753, while DATETIME2 offers a wider date range, greater precision for fractional seconds, and is…
Advertisement
AModel answer
DATE stores only a calendar date without any time component, DATETIME stores both a date and time but with a fixed precision and a limited date range going back to the year 1753, while DATETIME2 offers a wider date range, greater precision for fractional seconds, and is generally the recommended choice for new development.
CREATE TABLE Events (
EventDate DATE,
CreatedAt DATETIME2(3)
);Real-world example
A scheduling application stores the actual event date using the DATE type since time is not relevant, while using DATETIME2 for the more precise creation timestamp needed for auditing purposes.
Likely follow-ups
- Why is DATETIME2 generally recommended over the older DATETIME type?
- What does the number in DATETIME2(3) actually represent?
Related topics