Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Convert Nvarchar to smalltime or datetime

Author  Topic 

wira_chen
Starting Member

4 Posts

Posted - 2005-12-27 : 20:37:18
Hai Bro,
I need your help to convert a type nvarchar to datetime or smalldatetime.
Datetime (nvarchar) or date(nvarchar) time(nvarchar)
2005 8 25 12 5 18 2005 8 25 12 5 18

Results :
Datetime (datetime type) date(smalldatetime) timesmalldatetime)
2005:8:25 12:05:18 PM 2005:08:25 12:05:18 PM

Thank's for your interests Bro.

Regards

Wira Chan

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-12-27 : 21:19:03
Hi Wira Chan,

I'm not clear on your requirements. Is this a single value in a table or 2 values or what?
>>2005 8 25 12 5 18 2005 8 25 12 5 18

Read this link: How to post a question for a database
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-28 : 02:18:30
This is the Forum to contribute workable scripts. Hereafter post your questions at relevent forum like Developer

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2005-12-28 : 02:57:33
[code]
DECLARE @wtf NVARCHAR(20)
SET @wtf = '2005 8 25 12 5 18'

SELECT CAST(REPLACE(RTRIM(LEFT(@wtf,10)), ' ','.')
+ ' '
+ REPLACE(LTRIM(RIGHT(@wtf,8)), ' ', ':') AS DATETIME)

------------------------------------------------------
2005-08-25 12:05:18.000

(1 row(s) affected)
[/code]
This is not even fun. You should change this via some scripting language before importing it into SQL Server.

--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs
Go to Top of Page
   

- Advertisement -