Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us