October 10, 2018 at 7:35 am
Hi Experts,
Please help me in Nvarchar to Datetime, my scenario is as below
I'm getting data in NVARCHAR and format is "03\15\2010 01" i want this to be in DATETIME format like data "03-15-2010 01:00:00.000".
I've tried below but no luck
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SELECT CONVERT(datetime, stuff(stuff(stuff(@ndate,3,0,'/'),6,0,'/'),8,0,'/'), 101)
Expecting result to be like 2010-03-15 01:00:00.000
Thanks in Advance
October 10, 2018 at 7:52 am
SELECT CONVERT(DATETIME,REPLACE('03\15\2010 01','\','/')+':00:00')
--Jeff Moden
Change is inevitable... Change for the better is not.
October 10, 2018 at 7:58 am
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SET @Ndate = @ndate + ':00:00'
SELECT CONVERT(datetime, @ndate, 101)
October 10, 2018 at 8:30 am
Keith Oliver - Wednesday, October 10, 2018 7:58 AMDECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SET @Ndate = @ndate + ':00:00'
SELECT CONVERT(datetime, @ndate, 101)
The OP has "\"s in the dates.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 10, 2018 at 8:55 am
Bujji1987 - Wednesday, October 10, 2018 7:35 AMHi Experts,Please help me in Nvarchar to Datetime, my scenario is as below
I'm getting data in NVARCHAR and format is "03\15\2010 01" i want this to be in DATETIME format like data "03-15-2010 01:00:00.000".
I've tried below but no luck
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SELECT CONVERT(datetime, stuff(stuff(stuff(@ndate,3,0,'/'),6,0,'/'),8,0,'/'), 101)Expecting result to be like 2010-03-15 01:00:00.000
Thanks in Advance
You've put:
NVARCHAR and format is "03\15\2010 01"
then you've put:
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
Which one is it?
October 10, 2018 at 9:14 am
Jonathan AC Roberts - Wednesday, October 10, 2018 8:55 AMBujji1987 - Wednesday, October 10, 2018 7:35 AMHi Experts,Please help me in Nvarchar to Datetime, my scenario is as below
I'm getting data in NVARCHAR and format is "03\15\2010 01" i want this to be in DATETIME format like data "03-15-2010 01:00:00.000".
I've tried below but no luck
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SELECT CONVERT(datetime, stuff(stuff(stuff(@ndate,3,0,'/'),6,0,'/'),8,0,'/'), 101)Expecting result to be like 2010-03-15 01:00:00.000
Thanks in Advance
You've put:
NVARCHAR and format is "03\15\2010 01"
then you've put:
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
Which one is it?
Except for replacing backslashes with slashes, it won't actually matter. SQL Server will handle both without having to identify which format it's in IF you have the proper language settings.
SELECT CONVERT(DATETIME,REPLACE('03\15\2010 01','\','/')+':00:00')
,CONVERT(DATETIME,REPLACE('2010/03/15 01','\','/')+':00:00') --Of course, REPLACE is overkill for this one.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 10, 2018 at 9:21 am
Jeff Moden - Wednesday, October 10, 2018 9:14 AMJonathan AC Roberts - Wednesday, October 10, 2018 8:55 AMBujji1987 - Wednesday, October 10, 2018 7:35 AMHi Experts,Please help me in Nvarchar to Datetime, my scenario is as below
I'm getting data in NVARCHAR and format is "03\15\2010 01" i want this to be in DATETIME format like data "03-15-2010 01:00:00.000".
I've tried below but no luck
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
SELECT CONVERT(datetime, stuff(stuff(stuff(@ndate,3,0,'/'),6,0,'/'),8,0,'/'), 101)Expecting result to be like 2010-03-15 01:00:00.000
Thanks in Advance
You've put:
NVARCHAR and format is "03\15\2010 01"
then you've put:
DECLARE @ndate nvarchar(50) = N'2010/03/15 01'
Which one is it?Except for replacing backslashes with slashes, it won't actually matter. SQL Server will handle both without having to identify which format it's in IF you have the proper language settings.
SELECT CONVERT(DATETIME,REPLACE('03\15\2010 01','\','/')+':00:00')
,CONVERT(DATETIME,REPLACE('2010/03/15 01','\','/')+':00:00') --Of course, REPLACE is overkill for this one.
So this works:SET LANGUAGE us_english;
SELECT CONVERT(DATETIME,REPLACE('03\15\2010 01','\','/')+':00:00')
,CONVERT(DATETIME,REPLACE('2010/03/15 01','\','/')+':00:00') --Of course, REPLACE is overkill for this one.
But this doesn't:SET LANGUAGE British;
SELECT CONVERT(DATETIME,REPLACE('03\15\2010 01','\','/')+':00:00')
,CONVERT(DATETIME,REPLACE('2010/03/15 01','\','/')+':00:00') --Of course, REPLACE is overkill for this one.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply