SQL Interview: 94 SQL Server understanding of date strings

SQL Interview: 94 SQL Server understanding of date strings

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Development Level: Medium

Question:

If you pass the following string to SQL Server, will it always reliably be understood as 7th October 2025 by the date, datetime, and datetime2 data types?

'2025-10-07'

If not, why not?

Answer:

No, while that is true for date, and datetime2, the value that will be cast for the datetime data type depends upon the regional settings. For example, in British English, a string in the format ‘XXXX-XX-XX’ will be read as ‘YYYY-DD-MM’.

2025-12-06