I tried to store data in a table with SQL Server, but the problem is when inserting data it accepts YYYY-MM-DD but not DD-MM-YYYY, the column is type date
The code is
INSERT INTO datetime2022 (ΗΜΕΡΟΜΗΝΙΑ)
VALUES ('26-12-2022');
And the error message is:
Msg 241, Level 16, State 1, Line 3
Conversion failed when converting date and/or time from character string.
But with the code:
INSERT INTO datetime2022 (ΗΜΕΡΟΜΗΝΙΑ)
VALUES ('2022-12-30')
All is ok, need the table to accept date in ddmmyyyy format
CodePudding user response:
You can use DateFormat DMY
Example
Set DateFormat DMY
Declare @YourTable Table ([SomeDT] datetime)
Insert Into @YourTable Values
('26-12-2022')
Select * From @YourTable
Results
SomeDT
2022-12-26 00:00:00.000