sql inserts the wrong datetime into table [closed]

0

I'm using microsoft sql manager, and was trying to insert a date into my table, the problem is that it's inserting the wrong date, I make the following command for the manager's table

INSERT
INTO tblCliente /*minha tabela que eu criei*/
VALUES('Ze',1999-10-02,1) /*atributos da tabela:nome[nvarchar[50]],data[datatime],limiteCliente[decimal(18,2)]*/

But when you click to run the table code, this happens

Can someone tell me how to solve this problem?

    
asked by anonymous 21.04.2017 / 22:08

2 answers

1

What happened is that the value 1999-10-02 was considered as a numeric expression:
     1999 - 10 - 2 = 1987
And this numeric value was added to the smallest date value available for datetime, which is 1/1/1900. Something similar to:

-- código #3
SELECT dateadd(day, 1999-10-02, 0)

As the second column is declared as datetime , I recommend that you enter the value between apostrophes. For example:

-- código #1
INSERT into tblCliente
   VALUES('Ze', '19991002', 1);

That way, no hyphens.

You can also use the Convert function if you want to enter the date in another format. For example, to enter the date in dd / mm / yyyy format:

-- código #2
INSERT into tblCliente
   VALUES('Ze', convert(datetime, '2/10/1999', 103), 1);
    
24.04.2017 / 01:30
0

Please try as follows

INSERT INTO tblClient VALUES ('Zé', '1999-10-02', 1)

The date has to be entered as a string.

    
27.04.2017 / 01:55