简体   繁体   中英

How to get month from To_CHAR in oracle?

I'm using To_Char to convert a date to a string in the following format:

To_char(Date,'DD Month YYYY HH24:MI')

This works great however it returns the month with some spaces. I guess it's desgined such that all the month strings have the same lenght:

Current result

01 January  2020 13:15
01 February 2020 13:15
01 March    2020 13:15       << Spaces after the month string
01 April    2020 13:15       << Spaces after the month string
01 May      2020 13:15       << Spaces after the month string
01 June     2020 13:15       << Spaces after the month string

Desired result

01 January 2020 13:15
01 February 2020 13:15
01 March 2020 13:15       << No spaces after the month string
01 April 2020 13:15       << No spaces after the month string
01 May 2020 13:15         << No spaces after the month string
01 June 2020 13:15        << No spaces after the month string

Does anyone know how to achieve that please directly from To_char function? (without doing some specific string replacements like replace(To_char(Date,'DD Month YYYY HH24:MI'),' double spaces ',' single space ');

Thanks Cheers,

You can use the fm modifier on month :

select to_char(sysdate,'DD FMMonth YYYY HH24:MI')
from dual

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM