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!

Adding Time

Status
Not open for further replies.

woyler

Programmer
Jun 20, 2001
678
US
Is there a way to add time intervals(not time of day) in the format of hh:mm:ss for use in a SP?
i.e.
01:20:10 + 2:30 = 01:22:40

Thanks,
Bill
 
yes, see DateAdd(one of d/dd/y/yy/m/mm/,date,dateToAdd) John Fill
1c.bmp


ivfmd@mail.md
 
Please correct me if I am wrong, but the arguments for DateAdd are DateAdd(datepart,number,date)
Say I am adding:
26:20:10 (26 hours,20mins,10sec)
+10:10:10 (10hours,10mins,10sec)
total: 36:30:10 (36hours,30mins,10sec)

Doesn't the DateAdd function use a 12 or 24 hour time base? The date part requirement could be used only for on part of the time I am adding, and the number parameter needs to be a whole number to add to the specified 'datepart'
So DateAdd("hh","mm","ss",26:20:10,10:10:10) or any variation thereof will not work.
 
No,
use one of DateAdd(ss,yourDate,numberOfCeconds)
DateAdd(s,yourDate,numberOfCeconds)
DateAdd(second,yourDate,numberOfCeconds) wher you want to add seconds
hh/h/hour for hours and ..., without "" John Fill
1c.bmp


ivfmd@mail.md
 
How would you suggest working out the problem of when the sum is more than 59. 00:01:58 + 00:02:54
 
It'll automadically be added 1 to minutes:
--query
declare @xxx datetime
set @xxx = (select GetDate())
print @xxx
set @xxx = (select dateadd(s, 58, @xxx))
print @xxx
--result
Aug 10 2001 11:35PM
Aug 10 2001 11:36PM
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top