October 22, 2012 at 6:18 am
hi i am new to sql and i have the following problem
i am using the following query :
select cast (1157068800 as datetime)
but i am getting this error :
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
please help
thanks
sanjay
October 22, 2012 at 6:21 am
sanjay.dakolia (10/22/2012)
hi i am new to sql and i have the following problemi am using the following query :
select cast (1157068800 as datetime)
but i am getting this error :
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
please help
thanks
sanjay
well it depends on what 1157068800 *means* doesn't it?
that looks a lot like a unix date, which is the # seconds since 01/01/1970:
/*
declare @NumSeconds int
SET @NumSeconds = 1157068800
select dateadd(second,@NumSeconds,'19700101')
*/
Lowell
October 22, 2012 at 6:24 am
this value was suppose to be datetime but by mistake the column datatype was given integer so now i want to convert it back to datetime
October 22, 2012 at 6:30 am
sanjay.dakolia (10/22/2012)
this value was suppose to be datetime but by mistake the column datatype was given integer so now i want to convert it back to datetime
What date does 1157068800 represent?
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
October 22, 2012 at 6:30 am
sanjay.dakolia (10/22/2012)
this value was suppose to be datetime but by mistake the column datatype was given integer so now i want to convert it back to datetime
um, i don't think so.
if it was a direct convert to integer from SQL Server, the number would be 38959 as far as SQl server is concerned.
pretty sure my first guess is correct; it resolves to
'2006-09-01 00:00:00.000', so i'm pretty sure it was imported form another system as is, and was never a datetime in SQL that was accidentally stored in an integer column.
--returns 38959
select CONVERT(decimal,convert(datetime,'2006-09-01 00:00:00.000'))
Lowell
October 22, 2012 at 6:33 am
thanks a ton Lowell it worked
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply