CommencerCommencer gratuitement

Changing the date format

Remember that SQL Server can interpret character strings that look like dates in a different way than you would expect. Depending on your settings, the string "29-04-2019" could be interpreted as the 29th of April, or an error can be thrown that the conversion to a date was not possible. In the first situation, SQL Server expects a day-month-year format, while in the second, it probably expects a month-day-year and the 29th month does not exist.

In this exercise, you will instruct SQL Server what kind of date format you want to use.

Cet exercice fait partie du cours

Functions for Manipulating Data in SQL Server

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

DECLARE @date1 NVARCHAR(20) = '2018-30-12';

-- Set the date format and check if the variable is a date
SET DATEFORMAT ___;
SELECT ___(@date1) AS result;
Modifier et exécuter le code