Problem with inserting date value into MSSQL

I

Igal

I'm trying to insert a date value into MSSQL, the type of the sql filed
is: "smalldatetime"
and i'm trying to insert a text Variable that looks like this:
"19/02/2006".

.... SET update_date='" & Update_Date & "' ...

i get the message:

The conversion of char data type to smalldatetime data type resulted in
an out-of-range smalldatetime value
 
B

Bob Barrows [MVP]

Igal said:
I'm trying to insert a date value into MSSQL, the type of the sql
filed is: "smalldatetime"
and i'm trying to insert a text Variable that looks like this:
"19/02/2006".

... SET update_date='" & Update_Date & "' ...

i get the message:

The conversion of char data type to smalldatetime data type resulted
in an out-of-range smalldatetime value

Always use a universally standard format for supplying dates to a database.
The ISO standard, YYYYMMDD works very well. Here are a couple articles about
handling dates:
http://www.aspfaq.com/show.asp?id=2313
http://www.aspfaq.com/show.asp?id=2040
http://www.aspfaq.com/show.asp?id=2260


Further points to consider:
Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/72e36562fee7804e

Personally, I prefer using stored procedures.
http://groups.google.com/group/microsoft.public.inetserver.asp.general/msg/5d3c9d4409dc1701?hl=en&
 
I

Igal

in the end i used a functions that converts the date to SQL format
(YYYY/MM/DD)
and that worked fine.
but for this application nothing much u can do, it's very old code, and
i'm trying some how to polish, i'm php programmer, not asp actually :)
will prolly write a new one in time for the whole system.

this article is very interesting and helpful. thanks for the
information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top