I have a date column with several dates, I needed the query to display the date as
- January 1st of 1999 -
with the dashes.
Could anyone help?
Thank you
You can put fixed values in the date format mask by enclosing them in double quotes :
with t as (select date '1999-01-01' as dt from dual)
select to_char(dt, 'fm"-" Month ddth "of" YYYY "-"')
from t;
TO_CHAR(DT,'FM"-"MONTHDDTH"OF"YYYY"-"')
---------------------------------------
- January 1st of 1999 -
Or to show today's date:
select to_char(sysdate, 'fm"-" Month ddth "of" YYYY "-"') from dual;
TO_CHAR(SYSDATE,'FM"-"MONTHDDTH"OF"YYYY"-"')
-----------------------------------------------------
- October 2nd of 2013 -
The fm
'fill mode' modifier stops it padding the month name out with spaces, and removes the leading zero you'd normally get from dd
.
The double-quotes are actually optional around the dashes since they're allowed anyway ( 'fm- Month ddth "of" YYYY -'
works fine too), but in this case I'd probably quote them anyway to show they're unusual.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.