New Formatting Functions in DB2
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Database

#1: New Formatting Functions in DB2 Author: NASCAR9Location: California PostPosted: Wed Jul 26, 2017 6:42 pm
    —
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')
                               

#2:  Author: kolusuLocation: San Jose PostPosted: Thu Jul 27, 2017 1:01 pm
    —
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



MVSFORUMS.com -> Database


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group