IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to convert Timestamp into numeric field?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
arultm

New User


Joined: 03 Dec 2007
Posts: 7
Location: Mumbai

PostPosted: Thu Dec 06, 2007 11:45 am
Reply with quote

Hi,

Can we convert date in timestamp of type '2007-12-06-00.00.00.000000' in the table into numeric field like 20071206 and can we use it in WHERE clause for arithmetic comparision?
If so please inform how to do it?
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Dec 06, 2007 1:00 pm
Reply with quote

arultm,
Quote:
can we use it in WHERE clause for arithmetic comparision?

Can you please brief on your requirement with an example regarding what type of arithmetic comparision required?

Please check with the below code which retrieve the DATE in TIMESTAMP as INT(numeric) field.
Code:
---------+---------+---------+---------+---------+---------+----
SELECT INT(SUBSTR(CHAR(CURRENT_TIMESTAMP),1,4)||               
           SUBSTR(CHAR(CURRENT_TIMESTAMP),6,2)||               
           SUBSTR(CHAR(CURRENT_TIMESTAMP),9,2)) AS NUMERIC_DATE
FROM SYSIBM.SYSDUMMY1;                                         
---------+---------+---------+---------+---------+---------+----
NUMERIC_DATE                                                   
---------+---------+---------+---------+---------+---------+----
    20071206                                                   
DSNE610I NUMBER OF ROWS DISPLAYED IS 1                         
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 100     
---------+---------+---------+---------+---------+---------+----
Back to top
View user's profile Send private message
arultm

New User


Joined: 03 Dec 2007
Posts: 7
Location: Mumbai

PostPosted: Thu Dec 06, 2007 1:50 pm
Reply with quote

Hi,

I have to fetch rows from the table with date starting from 30/06/2005 to till now(today's date).
Each row has timestamp value which is the time of entry for that row in to the table.


Can I give

SELECT *
FROM tablename
WHERE INT(SUBSTR(CHAR(CURRENT_TIMESTAMP),1,4) > 2005
............... So on

directly...

Will it take more time to fetch values?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Dec 06, 2007 6:29 pm
Reply with quote

See this page for playing with dates

www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Dec 06, 2007 6:30 pm
Reply with quote

From there it indicates you could do the following, getting rid of that int/substr garbage. By doing that you ensure that your app is not portable(if that is a concern) because the default date format can change between databases.

Code:

SELECT *
FROM tablename
WHERE YEAR(CURRENT_TIMESTAMP) > 2005
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Dec 06, 2007 7:04 pm
Reply with quote

arultm,
Quote:
I have to fetch rows from the table with date starting from 30/06/2005 to till now(today's date).
Each row has timestamp value which is the time of entry for that row in to the table.

Please check with the below query for your requirement.
Code:
SELECT * FROM TABLE_NAME                   
WHERE DATE(COLUMN_TIMESTAMP)>='2005-06-30' 
  AND DATE(COLUMN_TIMESTAMP)<=CURRENT_DATE;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
Search our Forums:

Back to Top