The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Rate It (1)

Last post 04-13-2009 8:44 AM by gmmastros. 5 replies.

Sort Posts:

  • The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-19-2008, 5:04 AM
    • Member
      4 point Member
    • avijitgorai
    • Member since 03-27-2008, 9:48 AM
    • Posts 12

    Advance thanks ....... 

    My table is  TimeSheet:
    ----------------------------------- 

     CREATE TABLE [dbo].[TimeSheet](
        [autoid] [int] IDENTITY(1,1) NOT NULL,
        [UserId] [int] NOT NULL,
        [starttime] [datetime] NOT NULL,
        [endtime] [datetime] NOT NULL,
        [summary] [nvarchar](50) NOT NULL,
        [description] [nvarchar](50) NULL,
        [dtOfEntry] [datetime] NOT NULL,
        [Cancelled] [bit] NULL
    ) ON [PRIMARY]

     

    My Query is
    ------------------
    insert into timesheet
    (UserId, StartTime,EndTime, Summary, Description,DtOfEntry)
     values (2, '19/04/2008 2:05:06 PM', '19/04/2008 2:05:06 PM', '66', '6666','19/04/2008 2:05:06 PM')

    i m not able to insert value 

    Error Message is
    -------------------------
    Msg 242, Level 16, State 3, Line 1
    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
    The statement has been terminated.

     
    can any body give any solution 

     

    Avijit Gorai
  • Re: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-19-2008, 5:20 AM
    Answer
    • All-Star
      47,280 point All-Star
    • jimmy q
    • Member since 11-02-2006, 9:01 AM
    • Australia
    • Posts 3,231
    • Moderator
      TrustedFriends-MVPs

     When inserting datetimes, the format of the date time string is very important. The format of the date is dependant on the culture of your operating system and what collation the database is configured to be.

    In most default instances it will just be yyyy-MM-dd hh:mm:ss

    so try this

     

    insert into timesheet
    (UserId, StartTime,EndTime, Summary, Description,DtOfEntry)
     values (2, '2008-04-19 2:05:06 PM', '2008-04-19 2:05:06 PM', '66', '6666','2008-04-19 2:05:06 PM')

  • Re: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-19-2008, 5:30 AM

    in database, dateformat wil have to be like, yyyy,mm,dd

    eg: '2008/04/19 2:05:06PM' //this will work

    when you givw, 19/04/2008, then it will think that date is 2008, so it is giving error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

     

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-23-2008, 1:56 AM
    • Member
      4 point Member
    • avijitgorai
    • Member since 03-27-2008, 9:48 AM
    • Posts 12

     thanks for ur reply..................

    now i have change date format and its working............ 

    Avijit Gorai
  • Re: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-13-2009, 7:36 AM
    • Member
      535 point Member
    • Deeno20
    • Member since 03-25-2009, 7:21 AM
    • Kumavat
    • Posts 271

     Hi ,

     i m inserting the values in the fallowing ways 

    INSERT INTO LoginHistory([UserID],[LoginTime],[LoginIP])VALUES('NilCom1Ad01','13-04-2009 4:52:54 PM','127.0.0.1' )

     Still i  m Geting errror

     The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
    The statement has been terminated.

    Can u help me 

     

    Happy TO Help
  • Re: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

    04-13-2009, 8:44 AM
    • Contributor
      3,878 point Contributor
    • gmmastros
    • Member since 01-13-2009, 9:01 AM
    • Near Philadelphia, PA
    • Posts 594

    jimmy q:
    In most default instances it will just be yyyy-MM-dd hh:mm:ss

     

    There are 2 un-ambiguous date formats that SQL Server will NEVER mis-interpret.

    yyyy-mm-ddThh:mm:ss  (The T is a literal and must appear along with the data).  Ex: "2008-04-19T14:05:06"

    OR

    yyyymmdd h:mm:ss  Ex: "20080419 14:05:06"

     

    I prefer the second method because it is 'less strict' with the time data.  In the first format, you must use military time and the hour must be zero padded.  With the second format, the hour does not need to be zero padded and does not need to be in military format.

    -George
Page 1 of 1 (6 items)