3

I am using visual studio 2013 and I created this table with a date type column:

CREATE TABLE [dbo].[userTable]
(
[userId] INT NOT NULL PRIMARY KEY, 
[userName] VARCHAR(200) NOT NULL, 
[birthDate] DATE NOT NULL,
)  

and when I try to insert a date manually it gives me this error message:

enter image description here

I solved the problem by changing the date format from this:

2015/10/03

to this:

15/10/03

slugster
  • 49,403
  • 14
  • 95
  • 145
user2420263
  • 157
  • 1
  • 4
  • 15
  • 1
    Please show the code you're using to perform the insertion, and check that it really is the insertion that's failing. Currently we haven't got *nearly* enough idea of where the problem is to help you. – Jon Skeet Apr 17 '15 at 08:07
  • @JonSkeet there is no code, the OP tries to enter a value 'manually' as shown in the screenshot – huysentruitw Apr 17 '15 at 08:08
  • I maybe something like. You are not specifying the date in the right format. You are using `YYYY-MM-DD`. Are you sure that is the right format? Did you try with another format? – Arion Apr 17 '15 at 08:10
  • @WouterHuysentruit: Well it's not clear what that's a screenshot *of* to be honest. If there's no code involved, then the c# and asp.net tags are inappropriate. The question needs a *lot* more clarity, one way or the other. – Jon Skeet Apr 17 '15 at 08:10
  • Whats the format of the date you inserted? – Tushar Gupta Apr 17 '15 at 08:12
  • `YYYY-MM-DD` works for me in SSMS. Maybe table collation has an impact? – TZHX Apr 17 '15 at 08:14
  • @Jon Skeet you are right but added asp.net c# because I used it with sql server. – user2420263 Apr 17 '15 at 08:15
  • @ Tushar Gupta I didn't use any format because I don't where to add it. – user2420263 Apr 17 '15 at 08:16
  • By the way.. http://sqlfiddle.com/#!6/03317/2 – Soner Gönül Apr 17 '15 at 08:17
  • @user2420263: But if your question doesn't actually involve any code, surely this is just a matter of SQL server and whatever part of Visual Studio you're using. It's *really* important to make your question clear... – Jon Skeet Apr 17 '15 at 08:17
  • What are the language settings for your DB? – sr28 Apr 17 '15 at 08:18
  • @Arion when I created the table I wanted to add date format but I don't where to add it. – user2420263 Apr 17 '15 at 08:18
  • Using Visual Studio 2013 Premium connected to a SQL Server 2012 database I am unable to replicate this issue. It accepts the input fine. @JonSkeet is correct in that you need to add more information to your question before you can get an answer. This is almost certainly an issue with the database collation you are using. I notice from your screenshot that you are not using an English-language system, and so I assume that your database has been setup with that in mind. – TZHX Apr 17 '15 at 08:26
  • This shows you how to change the language settings: http://stackoverflow.com/questions/15705983/how-to-change-default-language-for-sql-server – sr28 Apr 17 '15 at 08:26
  • @user2420263 ,Did u try using sql server management studio without visual studio 2013.? – Hasanka Rathnayake Apr 17 '15 at 08:42

1 Answers1

1

Click on datetime on right buttom. - Change Date time setting - Change Date time setting - Change Calendar Setting Change the short date format accordingly.

The problem is because of the swapping between month and date. enter image description here

Prashant Ghimire
  • 4,890
  • 3
  • 35
  • 46
  • 1
    That may not be the optimal solution because with Date as type you can very well insert – Tushar Gupta Apr 17 '15 at 08:15
  • 1
    This does not answer the question. – TZHX Apr 17 '15 at 08:15
  • No. `YYYY-MM-DD` is the default string literal format for `Date` type. – Soner Gönül Apr 17 '15 at 08:15
  • Why do you think this is a solution? In what situation would doing the change you suggest help, when the date shown in the OP's screenshot would be equally valid in both for format you suggest they change *from* to the format you suggest they change *to*? – TZHX Apr 17 '15 at 08:32
  • @TZHX ... When you have 2008 version of SQL Server in VS, and I've tried and it works with the version of SQL server I have. – Prashant Ghimire Apr 17 '15 at 08:43
  • Yes... but can you replicate the user's problem with what you have? "2015-10-03" could be either 3rd October or 10th of March, so your "solution" doesn't make a difference to their outcome -- you're not *actually* answering the user's question. You say `The problem is because of the swapping between month and date. ` when it **clearly isn't**. – TZHX Apr 17 '15 at 08:46
  • Any version of Date including String months works with the version of SQL server I have, it could be the problem of SQL Server version of the questioner, probably. – Prashant Ghimire Apr 17 '15 at 08:49
  • That you have no idea what is causing the issue doesn't suggest to you that you shouldn't answer the question? – TZHX Apr 17 '15 at 09:07
  • @Prashant Ghimire your answer helped me, the date format in my computer is displayed like this: YY/MM/DD so I tried to change the date like this: 15/10/03 and it worked. – user2420263 Apr 17 '15 at 09:32
  • Thats good. I found out that it was common issue for some microsoft reasons. – Prashant Ghimire Apr 17 '15 at 09:34