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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arithmetics on Timestamp

Status
Not open for further replies.

PelleNo

Programmer
May 29, 2002
5
SE
I would like to calculate the difference between 2 fields, both declared as Timestamp(6).

A simple subtraction is not allowed can I cast or format in any way to get through with this !?

Best regards
PelleNo
 
PelleNo,

yes u can convert a timestamp to either date or time equivalent

say col1 contains 2002-05-21 17:43:30


u can use the below sql to get either the date part or the time part of it and then do normail manipulations...

to get date part...

select
cast(col1 as date format 'yyyymmdd')
from
table1


to get time part....
select
cast(col1 as time(0))
from
table1

 
Hi,
you can subtract 2 timestamps....However the difference between 2 timestamps is an interval. you must tell to parser which format you want the answer in.

sel column1 - column2 Day(4) to seconds(6)
from blort;

This means the answer would be the number of Days down to the second difference between the 2 dates.

You can review my note about intervals in....

thread328-150396


Maybe I should make this a FAQ....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top