[quoted text, click to view] On Fri, 07 Jul 2006 14:21:44 -0700, JL wrote:
>I am using VB.Net in VS2005 against SQL2005. I am writing an UPDATE
>query and getting an error on my date/time fields. An example of my
>query string is -
>DOB = #3/12/1949 12:00:00 AM"
>
>I get the error - "Incorrect syntax nar '12'
>
>The way I generate the above string is from a data table and I simply
>convert the field to a string. So I am confused why I get a syntax
>error?
>
>TIA,
>John
Hi John,
First, SQL Server uses single quotes (') to delimit date and time
constants, not hash symbols (#) or double quotes (").
Second. to prevent misinterpretation of the string (for instance, the
date above can be interpreted as march 12 or december 3, depending on
locale settings), you should stick to these formats:
* 'yyyymmdd' - date only. Note: no punctuation is used at all, just a
character string of 8 numeric characters. Time will default to midnight.
* 'yyyy-mm-ddThh:mm:ss' - date and time. Note: the parts of the date are
seperated by dashes; the parts of the time are seperated by colons and
an uppercase T seperates date from time.
* 'yyyy-mm-ddThh:mm:ss.mmm' - date and time with millisecond precision.
Note that SQL Server rounds to the nearest 1/300th second!
* 'hh:mm:ss' or 'hh:mm:ss.ttt' - time only. Date defaults to 1/1/1900.
--