SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 merge date and time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asif372
Posting Yak Master

Pakistan
100 Posts

Posted - 01/27/2013 :  03:53:49  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/27/2013 :  13:54:08  Show Profile  Reply with Quote
DATEADD(minute,DATEDIFF(minute,0,[Time]),[Date])

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/27/2013 :  13:54:45  Show Profile  Reply with Quote
see logic here

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shan007
Starting Member

USA
17 Posts

Posted - 01/27/2013 :  14:13:16  Show Profile  Reply with Quote
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..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/27/2013 :  14:20:47  Show Profile  Reply with Quote
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/

Go to Top of Page

shan007
Starting Member

USA
17 Posts

Posted - 01/27/2013 :  15:07:00  Show Profile  Reply with Quote
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..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/27/2013 :  23:53:31  Show Profile  Reply with Quote
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/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000