SQL Server: convert ((int)year,(int)month,(int)day) to Datetime [duplicate]

In order to be independent of the language and locale settings, you should use the ISO 8601 YYYYMMDD format – this will work on any SQL Server system with any language and regional setting in effect:

SELECT
   CAST(
      CAST(year AS VARCHAR(4)) +
      RIGHT('0' + CAST(month AS VARCHAR(2)), 2) +
      RIGHT('0' + CAST(day AS VARCHAR(2)), 2) 
   AS DATETIME)

Leave a Comment