dbTalk Databases Forums  

Convert nvarchar to datetime

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss Convert nvarchar to datetime in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Devibez
 
Posts: n/a

Default Convert nvarchar to datetime - 12-07-2005 , 11:39 AM






I have imported a dbf table into mssql in a char format 19720628.


How can I convert nvarchar to datetime?

Reply With Quote
  #2  
Old   
Danijel Novak
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-07-2005 , 01:07 PM






Hi,

Does 19720628 means 1972-06-28 as a date or is it a number?

--
Danijel Novak
MCP+I, MCSA, MCSE, MCDBA, MCT


"Devibez" <Devibez (AT) discussions (DOT) microsoft.com> wrote

Quote:
I have imported a dbf table into mssql in a char format 19720628.


How can I convert nvarchar to datetime?



Reply With Quote
  #3  
Old   
Devibez
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-07-2005 , 02:26 PM



Hi,

Yes! This is a date in a nvarchar data type format.

"Danijel Novak" wrote:

Quote:
Hi,

Does 19720628 means 1972-06-28 as a date or is it a number?

--
Danijel Novak
MCP+I, MCSA, MCSE, MCDBA, MCT


"Devibez" <Devibez (AT) discussions (DOT) microsoft.com> wrote in message
news:FDB32DD8-9A67-4E27-91B3-09534AAE8CEE (AT) microsoft (DOT) com...
I have imported a dbf table into mssql in a char format 19720628.


How can I convert nvarchar to datetime?




Reply With Quote
  #4  
Old   
GlennThomas5
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-07-2005 , 04:21 PM



DECLARE @str varchar(10)

SET @str = '19720628'

SELECT CONVERT(datetime, @str, 101)


Reply With Quote
  #5  
Old   
Devibez
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-07-2005 , 08:46 PM



Thanks!

How can I convert all the rows in a column using the method?


"GlennThomas5" wrote:

Quote:
DECLARE @str varchar(10)

SET @str = '19720628'

SELECT CONVERT(datetime, @str, 101)



Reply With Quote
  #6  
Old   
DLS
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-07-2005 , 10:28 PM



You can do an update:

UPDATE table
SET <datefield> = CONVERT(datetime, <datefield>, 101)

"Devibez" wrote:

Quote:
Thanks!

How can I convert all the rows in a column using the method?


"GlennThomas5" wrote:

DECLARE @str varchar(10)

SET @str = '19720628'

SELECT CONVERT(datetime, @str, 101)



Reply With Quote
  #7  
Old   
Devibez
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-08-2005 , 11:05 AM



Thank You!


For some reason when I try to run the upadate I receive the following error
message.

Do you you know why?


"Server: Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated."


Thanks Again!


"DLS" wrote:

Quote:
You can do an update:

UPDATE table
SET <datefield> = CONVERT(datetime, <datefield>, 101)

"Devibez" wrote:

Thanks!

How can I convert all the rows in a column using the method?


"GlennThomas5" wrote:

DECLARE @str varchar(10)

SET @str = '19720628'

SELECT CONVERT(datetime, @str, 101)



Reply With Quote
  #8  
Old   
GlennThomas5
 
Posts: n/a

Default Re: Convert nvarchar to datetime - 12-08-2005 , 12:53 PM



you should do a search so see if there are dates that are not in the
proper format. it sounds like there is a numeric value its trying to
convert that is out of sql's date range. you can use ISDATE to see
what values return 0 and those values are out of range.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.