0

Example query:

INSERT INTO Table
VALUES (CAST('13-07-2001' AS DATE))

Ends with

Conversion failed when converting date and/or time from character string.

Swapping month with day fixes the issue, but i would prefer using global system, not American.

2 Answers 2

1

Use a standard format. For SQL Server, YYYYMMDD always works for dates:

INSERT INTO Table (datecol)
    VALUES (CAST('20010713' AS DATE))

You should list the columns that you are inserting into, as well.

Sign up to request clarification or add additional context in comments.

Comments

0

In CAST and CONVERT (Transact-SQL) you can find that the style of your dates is 105.
So you can do it like this:

INSERT INTO Table
VALUES (CONVERT(DATE, '13-07-2001', 105))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.