Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I'm trying to insert a date '05/01/2015' (mm/dd/yyyy) But it saved like
' 1901-02-08 00:00:00.000 '

How can i insert it in correct way .. ?
Posted

INSERT INTO MyTable (MyDate) Values (GetDate())


OR

INSERT INTO MyTable (MyDate) Values (Convert(DateTime,'20150501',112))



try this
 
Share this answer
 
v2
Simple: pass it in ISO format: yyyy-MM-dd so 2015-05-01
or pass it as a DateTime object via a parametrized query.
Passing dates as strings always involves some "guesswork" on teh part of SQL, but ISO format should always be correct.
 
Share this answer
 
you can do it with convert function:

select CONVERT(datetime, '05/01/2015', 110)


see here: http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900