Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,i have a huge db and i wanna combine "date" fields with "time" fields.eg. date time 03/06/1979 1758 03/09/1979 1759 i wanna datetime 03/06/1979 17:58:00 03/09/1979 17:59:00
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2006-06-12 : 10:54:25
Use Proper DateTime datatype to avoid this type of conversions and related problems
declare @t table(d varchar(12), t int)insert into @tselect '03/06/1979', 1758 union allselect '03/09/1979', 1759 select cast(d+' '+substring(cast(t as varchar),1,2) +':'+substring(cast(t as varchar),3,2)+':00' as datetime) as Datesfrom @t
MadhivananFailing to plan is Planning to fail
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts
Posted - 2006-06-13 : 07:28:47
Here are a couple of alternatives...
--datadeclare @t table(d varchar(12), t int)insert into @t select '03/06/1979', 1758union all select '03/09/1979', 1759 --calculationselect cast(d+' '+stuff(cast(t as varchar(5)), 3, 0, ':') as datetime) as Dates from @t--orselect dateadd(mi, t / 100 * 60 + t % 100, cast(d as datetime)) from @t
Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part.