Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting DateTime vale

Status
Not open for further replies.

9654

Programmer
Aug 4, 2003
34
US
I have two parameters time in the format 10:40 and another parameter 30

What i need is to add and subtract 30min from 10:40 so that it will be 10:10 or 11:10 and subtract that from current datetime and get two datetime values.

Has anybody done this?
 
Try this.

declare @t1 datetime, @t2 int, @t3 int
set @t1= convert(datetime, '10:40')
set @t2 = 30
set @t3 = -30
select convert(varchar(5), dateadd(mi, @t2, @t1) , 108)
select convert(varchar(5), dateadd(mi, @t3, @t1) , 108)
 
Thanks mkal for the first part but i need to subtract these two time value from today's datetime and get two datetime values how do i do that?
 
just say ...

select getdate() +/- convert(varchar(5), dateadd(mi, @t2, @t1) , 108)

select getdate() +/- convert(varchar(5), dateadd(mi, @t3, @t1) , 108)
 
Please don't double post. You have this thread going and now you've created a second thread with the exact same question.

THREAD183-1044395

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top