MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

New Formatting Functions in DB2

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Jul 26, 2017 6:42 pm    Post subject: New Formatting Functions in DB2 Reply with quote

The forum has been slow so I figured I post something.
Just came across this function:
Code:
 VARCHAR_FORMAT

Read up on it, it's powerful. Many more formats available.

I use to do this:
Code:

                            SUBSTR(CHAR(BIRTH_DATE),1,4)
                        ||  SUBSTR(CHAR(BIRTH_DATE),6,2)
                        ||  SUBSTR(CHAR(BIRTH_DATE),9,2)

 


Now I do this:
Code:
VARCHAR_FORMAT(BIRTH_DATE,'YYYYMMDD')
                               

_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12357
Topics: 75
Location: San Jose

PostPosted: Thu Jul 27, 2017 1:01 pm    Post subject: Reply with quote

NASCAR9,


Thanks for sharing. I would prefer using TO_CHAR instead of Varchar format as it would give you extra 2 bytes for length.

Code:

SELECT TO_CHAR(CURRENT DATE,'YYYYMMDD')     
  FROM SYSIBM.SYSDUMMY1                     
  ;                                         
or
SELECT TO_CHAR(CURRENT DATE,'MMDDYYYY')     
  FROM SYSIBM.SYSDUMMY1                     
  ;                                         
or
SELECT TO_CHAR(CURRENT DATE,'DD-MON-YYYY') 
  FROM SYSIBM.SYSDUMMY1                     
  ;                                         

You can also format the numbers with comma's as shown in this topic

https://www.mvsforums.com/helpboards/viewtopic.php?t=12393
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group