SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Unable to convert date into smalldatetime


Unable to convert date into smalldatetime

Author
Message
amit-470969
amit-470969
SSC-Enthusiastic
SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)

Group: General Forum Members
Points: 111 Visits: 242
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?
Key DBA
Key DBA
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1711 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
Prasad Bhogadi
Prasad Bhogadi
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2475 Visits: 450
Try this
SELECT CAST(GETDATE() AS SMALLDATETIME)

Prasad Bhogadi
www.inforaise.com
amit-470969
amit-470969
SSC-Enthusiastic
SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)

Group: General Forum Members
Points: 111 Visits: 242
hi Prasad,

i have already tried this . but same result here.

Thanks
amit-470969
amit-470969
SSC-Enthusiastic
SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)SSC-Enthusiastic (111 reputation)

Group: General Forum Members
Points: 111 Visits: 242
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.
dreamslogic
dreamslogic
SSC Veteran
SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)SSC Veteran (233 reputation)

Group: General Forum Members
Points: 233 Visits: 203
Try this

SELECT CAST (floor (cast(getdate () AS SmallDatetime )) AS
Rudyx - the Doctor
Rudyx - the Doctor
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10906 Visits: 2503
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."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search