SQL Dates

Working with dates in SQL

Data types

SQL Dates: Field types

DATETIME2

DATETIME2 has more precision than DATETIME. It is recommended by Microsoft for new projects. There is a great write up here: DATETIME @ Database.guide.

Usage:

Can be used with or without a precision qualifier. No qualifier defaults to 7 digits in the millisecond/nanosecond segment.

  • DATETIME2

  • DATETIME2(7)

SQL Dates: DateTime2

Converting SQL date format

SQL Dates

Selecting Part of a Date

SQL Dates: Date Part