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
 Next half an hour time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ranjit.ileni
Posting Yak Master

India
182 Posts

Posted - 05/16/2011 :  04:20:42  Show Profile  Reply with Quote
Hi,
Explmple:


2011-05-16 14:06:24.747 to 2011-05-16 14:30:00.000

2011-05-16 13:45:24.747 to 2011-05-16 14:00:00.000

2011-05-16 13:06:24.747 to 2011-05-16 13:30:00.000



here is the sample table

create table #temp
(
startdate datetime
,enddate datetime
)

insert into #temp
select '2011-05-16 13:35:54.930','2011-05-16 13:00:54.930' union all
select '2011-05-16 22:45:54.930','2011-05-16 13:5:54.930' union all
select '2011-05-16 13:58:54.930','2011-05-16 13:15:54.930' union all
select '2011-05-16 13:30:54.930','2011-05-16 13:29:54.930'

select * from #temp
-- Expected output:
I need to convert field to next half an hour
(ex: 12:35:00.000 to 13:00:00.000 ond 12:12:00.000 to 12:30:00.0000)

-- Expected output:
startdate enddate
2011-05-16 14:00:00.000 2011-05-16 13:30:00.000
2011-05-16 23:00:00.000 2011-05-16 13:30:00.000
2011-05-16 14:00:00.000 2011-05-16 13:30:00.000
2011-05-16 14:00:00.000 2011-05-16 13:30:00.000

Please help me

--Ranjit

Edited by - Ranjit.ileni on 05/16/2011 04:39:32

Ranjit.ileni
Posting Yak Master

India
182 Posts

Posted - 05/16/2011 :  04:55:10  Show Profile  Reply with Quote
Sorry ,

I got it by using following query.

select
dateadd(minute,30,dateadd(minute,(datediff(minute,0,startdate)/30)*30,0))startdate
,dateadd(minute,30,dateadd(minute,(datediff(minute,0,enddate)/30)*30,0))enddate
from #temp

--Ranjit
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30276 Posts

Posted - 05/16/2011 :  05:29:06  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Simplify...
SELECT	StartDate,
	DATEADD(MINUTE, DATEDIFF(MINUTE, '00:00:00', StartDate) / 30 * 30, '00:30:00'),
	EndDate,
	DATEADD(MINUTE, DATEDIFF(MINUTE, '00:00:00', EndDate) / 30 * 30, '00:30:00')
FROM	#Temp



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Ranjit.ileni
Posting Yak Master

India
182 Posts

Posted - 05/16/2011 :  06:01:38  Show Profile  Reply with Quote
Thanks Peso,

I'll use your code

--Ranjit
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.05 seconds. Powered By: Snitz Forums 2000