robert
robert

Reputation: 321

insert into date query give me wrong date sql server

when i try this query in the sql server query edit

INSERT INTO table ( postdate) Values (07/09/2010 )

or

INSERT INTO table ( postdate) Values (cast (07/09/2010 as datetime)

it insert this 1/1/1900 12:00:00 AM

so why i'm missing here???

Upvotes: 0

Views: 3719

Answers (2)

gbn
gbn

Reputation: 432261

07/09/2010 = 7 divided by 9 divided by 2010 with integer arithmetic

This of course gives zero which is 01 Jan 1900 00:00:00.000

Use SQL Server "safe" ISO (yyyymmdd) + delimiters

INSERT INTO table ( postdate) Values ('20100907')

Upvotes: 2

Nishant
Nishant

Reputation: 55866

        INSERT INTO table ( postdate) Values ('2010-09-07' )

Upvotes: 3

Related Questions