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

Return Timestamp as numeric value


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

Active User


Joined: 29 Oct 2010
Posts: 202
Location: Toronto, ON, Canada

PostPosted: Wed Feb 23, 2011 12:37 am
Reply with quote

The below sql expression will return a Timestamp column as a pure numeric value ie. no dashes or periods. Is there an simplier way of doing this?

REPLACE(REPLACE(CHAR(timestamp_column), '-', ''), '.', '')
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Feb 23, 2011 1:41 pm
Reply with quote

varchar_format(current timestamp,'YYYYMMDDHH24MISSNNNNNN')

publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_bif_varcharformat.htm

also usefull for julian date, week, quarter,...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 23, 2011 1:56 pm
Reply with quote

though the data is all numbers, without a CAST, it is still CHAR datatype.
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 202
Location: Toronto, ON, Canada

PostPosted: Wed Feb 23, 2011 7:36 pm
Reply with quote

GuyC wrote:
varchar_format(current timestamp,'YYYYMMDDHH24MISSNNNNNN')

publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_bif_varcharformat.htm

also usefull for julian date, week, quarter,...


Unfortunately we are still using version 8 of DB2. It has the VARCHAR_FORMAT function but allows for only one string value 'YYYY-MM-DD HH24:MI:SS' which is silly. I guess I have to wait until we upgrade

FYI - I was looking for a CHAR format but with just numbers
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Feb 23, 2011 7:39 pm
Reply with quote

Code:
(timestamp_column + 1 year + 1 month + 1 day - '0001-01-01-00.00.00.000000')


You may have to change the format of the literal depending on your default date format.
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 Return codes-Normal & Abnormal te... JCL & VSAM 7
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Timestamp difference and its average ... DB2 11
Search our Forums:

Back to Top