If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > datediff problems.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 17:14
bgame bgame is offline
Registered User
 
Join Date: Nov 2003
Posts: 23
datediff problems.

Hi all, I have quite a conundrum, at least for me.

I need to get the difference in minutes between the current date and a timestamp. However, I have two timestamp fields. The first one could be NULL (TIMESTAMP_1). The second one is never NULL(TIMESTAMP2). What I want to do is say give me the datediff between the max of TIMESTAMP_1 or TIMESTAMP_2 and the current time.

This is what I tried to select:

datediff(mi,max(isnull(TIMESTAMP_1,TIMESTAMP_2)),g etdate())

However, it grabs TIMESTAMP_1 if it's there and if not then it grabs TIMESTAMP_2. How can I tell it to take the max of both?

This is Sybase ASE 12.5.

Thanks for any help.
Reply With Quote
  #2 (permalink)  
Old 02-13-04, 16:34
mkkmg mkkmg is offline
Registered User
 
Join Date: Oct 2003
Location: Dallas
Posts: 76
....

well this is using sql server so code might be a bit different but same concept should be able to be used.

case when timestamp1 > timestamp2 then DATEDIFF(mi, timestamp1, getdate())
when timestamp1 < timestamp2 then DATEDIFF(mi, timestamp2, getdate())
ELSE DATEDIFF(mi, timestamp1, getdate()) END
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On