Saturday, May 5, 2018

Using the TO_CHAR Function with Dates

https://randomsrsolutions.blogspot.com/2018/05/using-tochar-function-with-dates.html

DD                                    01-31
MON                                JAN, FEB,.......... DEC
Mon                                  Jan, Feb, ...............Dec
MONTH                           JANUARY, FEBRUARY, ...... DECEMBER
Month                               January, February, ................ December
YY                                    01, 02, 03 ......                            (Century)
RR                                    01, 02, 03 ......                            (Century)
YEAR                               SPELL OUT YEAR
Year                                  Spell Out Year
HH12                               1 - 12
HH24                               0 -23
AM       
PM
MI                                     01 - 59 MINUTES
SS                                     01 - 59 SECONDS
DY                                    MON, TUE, ............ SUN
Dy                                     Mon, Tue, ................ Sun
DAY                                  MONDAY, TUESDAY, ................ SUNDAY
Day                                   Monday, Tuesday, ................ Sunday


How to Display Time Portion

select to_char(sysdate,'DD-MON-YY HH24:MI:SS AM') from dual;
05-MAY-18 22:37:46 PM

select to_char(sysdate,'DD-MON-YY HH12:MI:SS AM') from dual;
05-MAY-18 10:37:46 PM

select to_char(sysdate,'DD-MON-YY HH12:MI:SS') from dual;
05-MAY-18 10:37:46

select to_char(sysdate,'HH12:MI:SS') from dual;
10:37:46

select to_char(sysdate,'HH12:MI:SS AM') from dual;
10:37:46 PM

select to_char(sysdate,'HH24:MI:SS') from dual;
22:37:46

select to_char(SYSDATE,'DD/MM/YY HH12:MI:SS AM') from dual;
05/05/18 10:37:46 PM

select to_char(SYSDATE,'DD/MM/RR HH12:MI:SS AM') from dual;
05/05/18 10:37:46 PM

select to_char(SYSDATE,'DD/MM/RRRR HH12:MI:SS AM') from dual;
05/05/2018 10:37:46 PM

Adding 3 Days

select to_char(SYSDATE,'DD-MON-RR HH24:MI:SS'),
to_char(SYSDATE+3, 'DD-MON-RR HH24:MI:SS') from dual;
05-MAY-18 22:37:46      08-MAY-18 22:37:46

select to_char(SYSDATE,'DAY, MONTH DD RRRR') from dual;
SATURDAY ,MAY    05 2018

select to_char(SYSDATE,'Day, Month DD RRRR') from dual;
Saturday ,May    05 2018

select to_char(SYSDATE+31,'Day, Mon DD RRRR') from dual;
Tuesday ,Jun     05 2018

select to_char(SYSDATE+31,'Dy, Mon DD RRRR') from dual;
Tue ,Jun    05 2018

select to_char(SYSDATE+31,'DAY Day DY Dy') from dual;
TUESDAY  Tuesday    TUE    Tue

select to_char(SYSDATE,'DD DDTH DDSP DDSPTH Ddth DdSP DdSPTH') from dual;
05   05TH   FIVE    FIFTH   05th   Five     Fifth

select to_char(SYSDATE, 'MM Mmth MmSP MmSPTH MON Mon MONTH Month') from dual;
05     05th     Five     Fifth     MAY     May     MAY     May

select to_char(SYSDATE+31, 'MM Mmth MmSP MmSPTH MON Mon MONTH Month') from dual;
06    06th     SIX     Sixth      JUN    Jun     JUNE     June

select to_char(SYSDATE, 'YY RR YYYY RRRR YEAR, Year') from dual;
18   18   2018   2018   TWENTY EIGHTEEN,   Twenty Eighteen

select to_char(SYSDATE+31, 'DdTH "of" Month RRRR') from dual;
05th of June 2018

No comments:

Post a Comment

XLA to GL Link

  https://plsqlquery.blogspot.com/2025/12/xla-to-gl-link.html SELECT             acr.cash_receipt_id,             acr.receipt_number,       ...