Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to convert Timestamp into numeric field?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: How to convert Timestamp into numeric field?
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    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

See this page for playing with dates

http://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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts JES2 job size field matching Windows ... SRICOBSAS All Other Mainframe Topics 4 Tue Sep 05, 2017 5:49 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us