Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

T-SQL Date/Time Error

  • 15-04-2013 3:45pm
    #1
    Registered Users, Registered Users 2 Posts: 904 ✭✭✭


    Hi, can someone help here please, am having an issue with this statement and getting the error below.
    Thanks in advance.
    (P.S I have tried code 109, and 120 and same error)

    DECLARE
    @DATETIMEOUT DATETIME
    SELECT
    @DATETIMEOUT = dateadd( hour, datepart( hour, '17.28.39' ),

    convert( datetime, convert( varchar(10), '2009-09-09', 101 )))
    SELECT @DATETIMEOUT


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



Comments

  • Registered Users, Registered Users 2 Posts: 230 ✭✭bellylint


    It doesnt like the notation that you have for
    dateadd(hour,datepart(hour,'17.28.39'),

    I would hazard its is treating the 17.28.39 like you are trying to specify I date
    dateadd(hour,datepart(hour,'17:28:39') works


  • Registered Users, Registered Users 2 Posts: 904 ✭✭✭realgolfgeek


    thanks for the reply Belly, but not 100% what you mean,
    do you have an example or are you able to ammend my select statement please ?

    Thanks alot.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    Well you were told the solution above but I guess reading is hard for you.

    SQL Server does not like the . in the time i.e. 17.28.39 should 17:28:39.

    [PHP]
    DECLARE @DATETIMEOUT DATETIME
    SELECT @DATETIMEOUT =dateadd(hour,datepart(hour,'17:28:39'),

    convert(datetime,convert(varchar(10),'2009-09-09', 101 )))
    SELECT @DATETIMEOUT
    [/PHP]

    Out of interest what language/region is SQL Server using?


Advertisement