Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to insert date into sql database..
Without using sql parameters
Posted
Comments
Thanks7872 24-Dec-14 4:54am    
Just like you insert any other things. Theres nothing special about inserting dates in SQL Server.
Rajesh waran 24-Dec-14 4:58am    
Rohan,you are right.but not yet understand what OP want? i think he is not clear with his question? bcoz it tends to SQL injection.
Thanks7872 24-Dec-14 5:01am    
You are not alone in that case. No one can understand from such little info.
Kornfeld Eliyahu Peter 24-Dec-14 4:57am    
Why ban SQL parameters? Those are your friend in preventing SQL injection...
Member 10168792 24-Dec-14 6:20am    
Whenever I am going to insert date into database it give exception like 'Incorrect syntax near '00'

1 solution

Don't.

Always use SQL parameters - it removes any confusion from the system and means that your data is always consistent: which removes worse problems further down the line.

But...if you are alergic to them, then send it as a string in ISO 8601 format: yyyy-MM-dd
http://en.wikipedia.org/wiki/ISO_8601[^]
It's unambiguous and show convert without problems. Just remember to validate it if it is a user input!

But please, store it in a Date or DateTime column - don't be tempted to use a NVARCHAR or similar, it always ends in tears...
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 24-Dec-14 5:27am    
I think it is better stop at the "Don't" part...
OriginalGriff 24-Dec-14 5:32am    
I'd agree - but it's too short for the system to accept! :laugh:

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