all groups > sql server misc > september 2003 >
You're in the

sql server misc

group:

Date Format Errors


Date Format Errors des_crocker NO[at]SPAM harcourt.com
9/23/2003 7:14:01 AM
sql server misc:
Dear all,

I have an asp web application that submits SQL commands to our SQL 7
database. When trying to run one of the users queries with a date
selection where the days > 12 I get the following error:

[Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a
char data type to a datetime data type resulted in an out-of-range
datetime value.

We always store all our dates as yyyymmdd and this has always seemed
quite unambiguous. Strange thing is that it runs fine in QA, using a
date format of 'yyyy-mm-dd'. But when it tries to run through the asp
application on IIS using a system DSN ODBC to the SQL box it fails.

The select statement is this:

select distinct 'ADES0102XD', cci.customeraccount, cci.companyname ,
cci.fullname, cci.address1, cci.address2, cci.street, cci.address3,
cci.town, cci.county, cci.country, cci.postcode from customersales as
cs inner join customercontactinfo as cci on cs.customeraccount =
cci.customeraccount WHERE ((CS.OrderType = 3 OR CS.OrderType = 4) OR
CS.CustomerAccount LIKE 'PR%') AND (cs.hitdate >= '2003-1-31' and
cs.hitdate <= '2003-2-25')

Why is it failing when coming through the IIS/DSN ODBC route, but
works ok if I run it myself in QA? I have tried adding 'set dateformat
ymd' into my asp code but to no avail. Are there some date format
settings on the IIS box that I don't know about? I've tried changing
the default language on the login account between British English and
English, but this has not solved the problem. The client, IIS and
server box are all set to English (United Kingdom) region settings.

Cheers,

Re: Date Format Errors Ryan Waight
9/23/2003 3:19:39 PM
ODBC must be doing a conversion on the date, try running a Profiler Trace to
see what command is actually asked of the SQL Server. You could also try
passing the dates in a Long Date format so there is no ambiguity. eg '31 Jan
2003'

--
HTH
Ryan Waight, MCDBA, MCSE

[quoted text, click to view]

Re: Date Format Errors Jacco Schalkwijk
9/23/2003 4:31:13 PM
Well, there is only no ambiguity if the whole world speaks English ;-)

set language french
SELECT ISDATE('31 Jan 2003')

The only two really unambigous date formats in SQL Server are yyyymmdd and
yyyy-mm-ddThh:mi:ss.nnn


--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.


[quoted text, click to view]

Re: Date Format Errors des_crocker NO[at]SPAM harcourt.com
9/25/2003 2:58:53 AM
I ran a trace in Profiler:

RPC: Starting

declare @P1 int
declare @P3 int
declare @P4 int
declare @P5 int
set @P1=0
set @P3=1
set @P4=8196
set @P5=0
exec sp_cursoropen @P1 output, N' select distinct ''ADES0102XD'',
cci.customeraccount, cci.companyname , cci.fullname, cci.address1,
cci.address2, cci.street, cci.address3, cci.town, cci.county,
cci.country, cci.postcode from customersales as cs inner join
customercontactinfo as cci on cs.customeraccount =
cci.customeraccount WHERE ((CS.OrderType = 3 OR CS.OrderType = 4) OR
CS.CustomerAccount LIKE ''PR%'') AND (cs.hitdate >= ''2003-1-31'' and
cs.hitdate <= ''2003-2-25'') ', @P3 output, @P4 output, @P5 output
select @P1, @P3, @P4, @P5



SP:StmtStarting

--
select distinct 'ADES0102XD', cci.customeraccount, cci.companyname ,
cci.fullname, cci.address1, cci.address2, cci.street, cci.address3,
cci.town, cci.county, cci.country, cci.postcode from customersales as
cs inner join customercontactinfo as cci on cs.customeraccount =
cci.customeraccount WHERE ((CS.OrderType = 3 OR CS.OrderType = 4) OR
CS.CustomerAccount LIKE 'PR%') AND (cs.hitdate >= '2003-1-31' and
cs.hitdate <= '2003-2-25')


As you can see the dates are fine, and the ODBC has not twisted them
at all. I've just upgraded my MDAC to 2.8 on the IIS box to match the
database and clients but to no avail.

The strange thing is that I put a copy of the application on another
IIS box (at a remote site) running Win2K and it works fine! But it
doesn't work on our local IIS box running NT4 SP5. Is this a clue?
There must be a configuration difference between the two IIS boxes
causing the problem.

I think my options now are to change the front end to write out the
dates in yyyymmdd format (which did work) or to find the difference
between the two IIS setups.

AddThis Social Bookmark Button