conversation of char data type to smalldatetime

  • Thread starter Thread starter Atilla Gunes
  • Start date Start date
A

Atilla Gunes

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


This problem comes from SqlException. In a program i wrote, Administrator
and one client have this problem everytime. But other clints don't face with
this problem. I think, problem occurs coz of Sql Server. Do u have an idea
??
 
Hi there, it seems to me that your casting (in SQL Server) has a problem.
This happens when you use convert and specify a wrong style code (third
parameter). To illustrate this check out the following example:

Declare @datechar Char(10)
Set @datechar = '30/04/2005' -- Day/Month/Year
Select Convert(SmallDateTime, @datechar, 101) /* FAILS!!! - The conversion
of char data type to smalldatetime data type resulted in an out-of-range

smalldatetime value */

but if I write it like this...

Select Convert(SmallDateTime,Convert(SmallDateTime, @datechar, 103),
101) -- OK!!! (2005-04-30 00:00:00)

Be aware of the expression format you want to convert into smalldatetime as
well of the style code used in the function.

Hope this may help you,

Regards,
 
Back
Top