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 > Database Server Software > DB2 > How to get Max timestamp of a Date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-29-08, 09:01
sushmitha sushmitha is offline
Registered User
 
Join Date: Aug 2008
Posts: 7
How to get Max timestamp of a Date

I am using DB2 first time. I have a table with Date, Time fields.
Field names are Date , Time

For each date we have many Claims with different timestamps.

But I need to get only the Claims with most recent timestamp into my query results

How Can I achieve this

Both Date and Time fields are Date data type

I tried using Max(Time) which is giving me some number 1/0/1900
Reply With Quote
  #2 (permalink)  
Old 08-29-08, 09:07
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What DB2 version and OS?
Reply With Quote
  #3 (permalink)  
Old 08-29-08, 09:14
sushmitha sushmitha is offline
Registered User
 
Join Date: Aug 2008
Posts: 7
Quote:
Originally Posted by ARWinner
What DB2 version and OS?
DB2 version 8. But I am not sure about OS
Reply With Quote
  #4 (permalink)  
Old 08-29-08, 09:20
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I would suggest that you find out what the OS (Operating System) is. It makes a lot of difference in the answers you will get. Some things are valid for Z/OS but not for Linux, or Windows, or Unix.

Andy
Reply With Quote
  #5 (permalink)  
Old 08-29-08, 09:28
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by sushmitha
Both Date and Time fields are Date data type
That is not possible. You cannot store a time in a DATE data type.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 09-01-08, 04:11
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by Marcus_A
That is not possible. You cannot store a time in a DATE data type.
I think there are just badly chosen column names.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 09-03-08, 08:32
sushmitha sushmitha is offline
Registered User
 
Join Date: Aug 2008
Posts: 7
Quote:
Originally Posted by Marcus_A
That is not possible. You cannot store a time in a DATE data type.
It is possible. I used Timestamp function to make it as a DateTime field and then did max(Datetime) field which is working like a charm
Reply With Quote
  #8 (permalink)  
Old 09-03-08, 08:43
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by sushmitha
It is possible. I used Timestamp function to make it as a DateTime field and then did max(Datetime) field which is working like a charm
Markus had a completely different point: a DATE value is not a timestamp and a TIMESTAMP value is not a date. Instead, a TIMESTAMP value is a combination of a DATE value and a TIME value. And you cannot store a TIME value in a value of type DATE. There is no arguing about it.

If you used the TIMESTAMP function on a DATE, you have a TIMESTAMP value as result - not a DATE value.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 09-03-08, 08:54
sushmitha sushmitha is offline
Registered User
 
Join Date: Aug 2008
Posts: 7
Quote:
Originally Posted by stolze
Markus had a completely different point: a DATE value is not a timestamp and a TIMESTAMP value is not a date. Instead, a TIMESTAMP value is a combination of a DATE value and a TIME value. And you cannot store a TIME value in a value of type DATE. There is no arguing about it.

If you used the TIMESTAMP function on a DATE, you have a TIMESTAMP value as result - not a DATE value.
I agree with it. But on the whole I need to see max(timestamp) for each date. When I did max(Timestamp) on Time field which gave me wrong results (I mentioned in my thread). If I do max(Timestamp(Date, Time)), I am getting it
Reply With Quote
  #10 (permalink)  
Old 09-03-08, 10:10
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Sorry, it's hard to understand what you try to say because you seem to mix data types with column names - e.g. "max(Timestamp) on Time field" doesn't make any sense. Is the column named "Timestamp" and has a data type "Time"? That's extremely confusing and you should fix this.

p.s: There are no "fields" in relational database systems. You have only "tables" with "rows" and "columns", and each row has a "value" for each column.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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