Microsoft
Software
Hardware
Network
Question : T-SQL DateTime conversion issue
I have an application that is passing a date to SQL server in the following format.
'20100212091459000000' (the parameter receiving this value is @DateTime varchar(20))
It appears that the actual date is being padded with zero's. for the stored procedure to return rows the date needs to be formatted like '20100212 09:14:59'
I've tried... SET @dDateTime = SUBSTRING('201002120914590
00000') which returns '20100212091459' I then tried CAST(@dDateTime AS DATETIME) and I get...
__________________________
__________
___
Msg 241, Level 16, State 1, Line 6
Conversion failed when converting datetime from character string.
.
Any suggestions are appreciated!
Answer : T-SQL DateTime conversion issue
declare @datetime varchar(100) = '20100212091459000000'
select cast ( stuff( stuff( stuff( LEFT(@datetime, 14) ,13,0, ':'), 11,0,':' ), 9, 0, ' ' ) as datetime )
Random Solutions
Need help designing feature to display info in textbox
Windows 7 (64Bit) printing to Windows XP (32Bit) shared printer
custom button wpf
How to call a 32 bit DLL from a 64 bit application.
Does wordpad support automation from vb.net?
How do I remove 'group on' in VB code for Access 2007 report?
Access ADP: Suppress "The SELECT permission was denied on the object database schema 'dbo'" message
How do I add an onclick action to a ButtonField inside a GridView?
Populate a DataTable from another DataTable
How do I restore "send to mail recipient"