Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert 'Nov 7' to datetime
Message
From
09/11/2018 15:48:22
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Convert 'Nov 7' to datetime
Environment versions
SQL Server:
SQL Server 2016
OS:
Windows 7
Miscellaneous
Thread ID:
01663259
Message ID:
01663259
Views:
66
Hey guys, I'm back

I'm trying to get something that looks like 'Nov 7 04:30' to convert to the equivalent SQL datetime value.
Everything I'm trying is bringing back 'Nov 7 2018 4:30 AM. I can get it as far as a string 2018-11-07 04:30, but it will not convert to a datetime

declare @fdate varchar(20), @f2 int, @f3 int, @f4 int, @t varchar(5), @nd varchar(20), @newdate datetime
set @fdate = 'Nov 07 04:30'
set @t = right(@fdate, 5)
print isdate(@fdate)
set @f2 = datepart(MM,@fdate) --str(@fdate,1,3))
set @f3 = convert(int, substring(@fdate, 5,2))
set @f4 = iif((@f2 = 12) and (datepart(MM, getdate()) = 1), year(getdate()) - 1, year(getdate()))
set @nd = str(@f4,4) + '-' + replace(str(@f2,2), space(1), '0') + '-' + replace(str(@f3,2), space(1), '0') + ' ' + @t
--set @nd = replace(str(@f2,2), space(1), '0') + replace(str(@f3,2), space(1), '0') + str(@f4,4)-- + @t
--set @newdate = convert(datetime, @nd)
set @newdate = cast(@nd as datetime)
print @f2
print @f3
print @f4
print @nd
print @newdate
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Next
Reply
Map
View

Click here to load this message in the networking platform