Connecting Tech Pros Worldwide Forums | Help | Site Map

How to insert dates using datetime functions.

Newbie
 
Join Date: Jul 2008
Posts: 1
#1: Jul 26 '08
Can any one help me in inserting any date into the table using insert command
because when i m trying to insert date using insert command the query executes but the date is totally wrong if i am inserting 6/29/1982 as date the output i get is 1900-01-01 00:00:00.000; and if i change it to 06- 29-1982 then the output comes right, I want to insert date using a gui application so what should be the format,,,,,,

Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 790
#2: Jul 27 '08

re: How to insert dates using datetime functions.


I presume that you are putting the query into a string variable in your fromt end.
Be sure to wrap the date up in its own quotes.

str="Update tbl set dte='06/29/2007' where key=1"

without the single quotes I thinke it would be treated as the mathematical expression
6 divided by 29 divided by 2007 which is close enough to 0
if you set a date filed to the number 0 you get the date
01-01-1900 00:00:00
The beginning of time according to microsoft

PS
I cannot explain why your second version worked
I would have thought it would be treated as a mathematical expression also ??
Reply


Similar Microsoft SQL Server bytes