Date format in oracle
4 answers
Try this using just one function call:
select to_char(sysdate, 'FMMM') from dual;
For details on the "FM" syntax, see Format Model Modifiers .
+2
source to share
One important thing to know about an FM operator is that it basically functions as a "switch". Think of the FM element as a prefix that acts on the entire element of the datetime element.
So in this case, when you only want the month, FMMM says essentially "return MM (month between 1 and 12), but leave trailing zeros".
If, for example, you used:
select to_char(sysdate, 'FMMMDD') from dual;
which will be interpreted to "return MMDD (month between 1 and 12, day between 1 and 31), but leave leading zeros for both month and day left blank .
If your date was August 8th, for example
select to_char(sysdate, 'MMMDD') from dual;
will return
0808
adding operator FM
select to_char(sysdate, 'FMMMDD') from dual;
will return
88
Notice how FM works throughout the entire datetime element.
0
source to share