Re: Searching on DATETIME Fields

From: Aaron Bertrand [MVP] (aaron_at_TRASHaspfaq.com)
Date: 03/19/04


Date: Fri, 19 Mar 2004 12:04:35 -0500


> I have seen that before, but my question is, why would passing 19/03/2004
> 00:00:00 to a field of type datetime, which does contain values in this
> format, fail?

Because you are using an ambiguous date format. You said you read the
entire article? Please use a standard format like YYYYMMDD, so SQL Server
doesn't have to guess whether 04/06/2004 is April 6th or June 4th.

-- 
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
>
> Surely passing the value is all that is required regardless of the
datatype
> as long as it matches the data contained in the field?
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote
in
> message news:eemPg0bDEHA.688@tk2msftngp13.phx.gbl...
> > All you need at:
> >
> > http://www.karaszi.com/sqlserver/info_datetime.asp
> >
> > -- 
> > Tibor Karaszi, SQL Server MVP
> > http://www.karaszi.com/sqlserver/default.asp
> >
> >
> > "Keith" <@.> wrote in message
> news:uqwYixbDEHA.1544@TK2MSFTNGP09.phx.gbl...
> > > I am fairly new to SQL so sorry if this is a really dumb question.
> > >
> > > I have a small (still) SQL database, which I am trying to query from
an
> > ASP
> > > page.
> > >
> > > The field I am querying is of DATETIME data type, and is populated
> > > automatically using the GetDate() function as a default value.
> > >
> > > When I try and search on this field, using a date/time in the format
> > > dd/mm/yyyy hh:mm:ss as the search criteria, it fails with 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.
> > >
> > > Can anyone tell me why this is?  Surely if I am passing a value in the
> > > correct format for the data stored in the field it should work?  Or am
I
> > > missing something.
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Inserting regional settings specific data into sql server
    ... All EU countries withouth the two English speaking use the format dd-MM-yy ... By using the parameters, while the program is in the right culture setting, ... than all those formats results using SQLparameters in the way the SQL server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Inserting regional settings specific data into sql server
    ... Italianyou will observe that the settings used are 10/02/2006 ... it a better idea to Format it using the string format functions or a very ... into the sql database.Sorry to bug the shorts off you but u now have context ... By using the parameters, while the program is in the right culture setting, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Moving a VBA function to SQL server
    ... SQL is a set-based language. ... "String Functions " in Books Online. ... This will produce a job header formatted like this: ... The format he specifies is stored in table 'Settings' - field 'JobHdrMask' ...
    (comp.databases.ms-access)
  • Re: How do I convert my dates to string in ADO
    ... and then format it the way I want it in the ... is easier to use Sql To do this. ... Microsoft SQL Server, ... file from a .CSV file which happens to be a report. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Prepare, SQL query with to_date call
    ... SQL query with to_date call ... The Oracle ODBC driver has a problem with date parameters although I'm ... using a date format containing the RR format. ...
    (perl.dbi.users)