| Author |
Topic  |
|
|
asif372
Yak Posting Veteran
Pakistan
90 Posts |
Posted - 01/27/2013 : 03:53:49
|
I have Data like this ------Date-------------------Time 2012-12-21 00:00:00.000 -----23:05 2012-12-21 00:00:00.000 -----23:05 2012-12-21 00:00:00.000 -----23:07 2012-12-21 00:00:00.000 -----23:08 2012-12-22 00:00:00.000 -----01:07 2012-12-22 00:00:00.000 -----06:59
i want data like this DateTime 2012-12-21 23:05:00.000 2012-12-21 23:05:00.000 2012-12-21 23:07:00.000 2012-12-21 23:08:00.000 2012-12-22 01:07:00.000 2012-12-22 06:59:00.000
how can it be possible thanks in advance
|
|
|
shenulal
Starting Member
India
11 Posts |
Posted - 01/27/2013 : 04:55:02
|
select cast(CONVERT(varchar(10),'2012-12-21 00:00:00.000',101) + ' ' + '23:05' as datetime)
Just replace the values with your field name
Hope this will help.
regards, shenulal |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/27/2013 : 13:54:08
|
DATEADD(minute,DATEDIFF(minute,0,[Time]),[Date])
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
|
|
shan007
Starting Member
USA
8 Posts |
Posted - 01/27/2013 : 14:13:16
|
Simplest solution, see below:
declare @date datetime declare @time time
select @date='2012-12-21 00:00:00.000' select @time='23:05'
select CAST(@date+@time as datetime)
output: 2012-12-21 23:05:00.000
============================== I'm here to learn new things everyday.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/27/2013 : 14:20:47
|
quote: Originally posted by shan007
Simplest solution, see below:
declare @date datetime declare @time time
select @date='2012-12-21 00:00:00.000' select @time='23:05'
select CAST(@date+@time as datetime)
output: 2012-12-21 23:05:00.000
============================== I'm here to learn new things everyday..
will work fine so long as original fields are of date/datetime and time datatypes. If varchar the format has to be consistent and unambiguos otherwise it will break
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
shan007
Starting Member
USA
8 Posts |
Posted - 01/27/2013 : 15:07:00
|
Yes, of course, I believe the field types used by asif is date/datetime time field. If they are varchar then he has to cast them date/time before concatenation..
============================== I'm here to learn new things everyday.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/27/2013 : 23:53:31
|
quote: Originally posted by shan007
Yes, of course, I believe the field types used by asif is date/datetime time field. If they are varchar then he has to cast them date/time before concatenation..
============================== I'm here to learn new things everyday..
Nope still missing my point
The cast will not work fine so long as date values are inconsistent or have an ambiguos format Read this
http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|