Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

T-SQL Date/Time Error

  • 15-04-2013 04: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