SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Date Conversion
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

afifimk
Starting Member

USA
22 Posts

Posted - 10/20/2008 :  15:58:16  Show Profile  Reply with Quote
I am not sure where to post this question, but here goes. I have NVARCHAR field where date/time is entered as '200810201045'. I need to convert that to a SQL small date time.

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/21/2008 :  00:08:41  Show Profile  Reply with Quote
select CAST(SUBSTRING('200810201045',1,8) + ' ' + SUBSTRING('200810201045',9,2) + ':'+RIGHT('200810201045',2) AS datetime)
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 10/21/2008 :  04:28:38  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Always use proper DATETIME datatype to store dates

Madhivanan

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

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 10/21/2008 :  05:07:13  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by visakh16

select CAST(SUBSTRING('200810201045',1,8) + ' ' + SUBSTRING('200810201045',9,2) + ':'+RIGHT('200810201045',2) AS datetime)


or
select cast(stuff(stuff('200810201045',11,0,':'),9,0,' ') as datetime)

Madhivanan

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

ssyssy
Starting Member

2 Posts

Posted - 11/05/2008 :  04:02:29  Show Profile  Reply with Quote
thank you
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 11/05/2008 :  04:08:42  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by ssyssy

thank you


Are you the one who asked the question?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000