Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Unable to convert date into smalldatetime Expand / Collapse
Author
Message
Posted Wednesday, December 26, 2007 9:26 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:54 AM
Points: 56, Visits: 227
hi,

i am using sql server 2005 and not able to convert date in to smalldatetime.

query:
select convert(smalldatetime,getdate())

Error:

Msg 298, Level 16, State 1, Line 1
The conversion from datetime data type to smalldatetime data type resulted in a smalldatetime overflow error.

why?


Post #436371
Posted Thursday, December 27, 2007 7:21 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, February 26, 2009 3:02 PM
Points: 515, Visits: 655
amit,


Your data in the DATETIME format may be out of the boundries of SMALLDATETIME.

DATETIME
January 1, 1753 through December 31, 9999


SMALLDATETIME
January 1, 1900 through June 6, 2079

Microsoft SQL Server Books online Topic: datetime and smalldate

Happy T-SQLing



"Key"
MCITP: DBA, MCSE, MCTS: SQL 2005, OCP
Post #436651
Posted Thursday, December 27, 2007 7:41 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, April 14, 2014 6:47 AM
Points: 967, Visits: 450
Try this
SELECT CAST(GETDATE() AS SMALLDATETIME)


Prasad Bhogadi
www.inforaise.com
Post #436661
Posted Thursday, December 27, 2007 11:57 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:54 AM
Points: 56, Visits: 227
hi Prasad,

i have already tried this . but same result here.

Thanks
Post #436800
Posted Thursday, December 27, 2007 12:10 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:54 AM
Points: 56, Visits: 227
Hi Damon,

thanks to reply.

i think that there is not a data range problem , because
here i m using getdate() for date.


actually when i try following query
>> Select Getdate()
i got result.


but when i try to convert or cast getdate into smalldatetime , so i m facing problem.

>> select cast (getdate() as smalldatetime)

i got error.

i think that its a sqlserver 2005 installation problem. because when i try same query on another sqlserver 2005 ,its working.


Post #436804
Posted Thursday, July 16, 2009 9:02 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 10:53 PM
Points: 27, Visits: 202
Try this

SELECT CAST (floor (cast(getdate () AS SmallDatetime )) AS
Post #754581
Posted Friday, July 17, 2009 8:16 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 11:26 PM
Points: 3,214, Visits: 2,336
both work for me:

select cast (getdate() as smalldatetime)

select convert(smalldatetime,getdate())

select @@version

results:


-----------------------
2009-07-17 09:16:00

(1 row(s) affected)


-----------------------
2009-07-17 09:16:00

(1 row(s) affected)


------------------------------------------------
Microsoft SQL Server 2005 - 9.00.4207.00 (X64)


(1 row(s) affected)





Regards
Rudy Komacsar
Senior Database Administrator

"Ave Caesar! - Morituri te salutamus."
Post #754855
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse