Tomb_Raider_Legend
Tomb_Raider_Legend

Reputation: 461

Converting a datetime in SQL

So I'm trying to convert this date but it doesn't really seem to work. What can the problem be? The Birthday has datetime as datetime!

INSERT Info
(Name, Birthday)
VALUES('Sara', CONVERT(datetime, 12-12-2015, 105));

This is the error message I get "Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query."

Upvotes: 1

Views: 89

Answers (1)

cbranch
cbranch

Reputation: 4769

Use quotes:

CONVERT(datetime, '12-12-2015', 105)

Without the quotes, SQL Server will interpret the expression as 12 minus 12 minus 2015.

or you can omit CONVERT and let SQL Server do the conversion implicitly:

INSERT Info
(Name, Birthday)
VALUES('Sara', '12-12-2015');

Upvotes: 6

Related Questions