Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Substract time to datetime field

Author  Topic 

jfha73
Starting Member

5 Posts

Posted - 2009-04-23 : 11:30:44
How do I accomplish this? I need to substract time from a datetime field.

Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 12:21:38
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, Col1), 0)
FROM Table1



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

jfha73
Starting Member

5 Posts

Posted - 2009-04-23 : 15:25:57
Where should i put the number of hours I want to substract?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 15:28:18
SELECT DATEADD(HOUR, -@HoursToSubstract, Col1)
FROM Table1



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

jfha73
Starting Member

5 Posts

Posted - 2009-04-23 : 15:31:08
anyway, I tried changing the zeros, but the column with the time that i want to change stays the same.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 15:34:58
Please post some sample data, some code you tried this far.
Also post your expected output.

Remember, we don't sit at your office and have access to your data.



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

jfha73
Starting Member

5 Posts

Posted - 2009-04-23 : 15:41:42
That last one worked, thanks.
Go to Top of Page
   

- Advertisement -