When I do...
Select TO_CHAR (date_field, 'Month DD, YYYY') from...
I get the following:
July 01, 2011 April 01, 2011 January 01, 2011
Why are there extra spaces between my month and day? Why doesn't it just put them next to each other?
Oracle TRIM() function removes spaces or specified characters from the begin, end or both ends of a string.
To set the date format: Select Preferences in the left frame, or select File, and then Preferences. Click the Planning icon, and then select Display Options. For Date Format, select MM-DD-YYYY, DD-MM-YYYY, YYYY-MM-DD, or Automatically Detect (to use your system's locale settings).
The Oracle TO_CHAR() function converts a DATE or INTERVAL value to a string in a specified date format. The Oracle TO_CHAR() function is very useful for formatting the internal date data returned by a query in a specific date format.
To_char formats a DATE into a string using the given format mask. To_date converts a STRING into a date using the format mask.
Why are there extra spaces between my month and day? Why does't it just put them next to each other?
So your output will be aligned.
If you don't want padding use the format modifier FM
:
SELECT TO_CHAR (date_field, 'fmMonth DD, YYYY') FROM ...;
Reference: Format Model Modifiers
if you use 'Month' in to_char it right pads to 9 characters; you have to use the abbreviated 'MON', or to_char then trim and concatenate it to avoid this. See, http://www.techonthenet.com/oracle/functions/to_char.php
select trim(to_char(date_field, 'month')) || ' ' || to_char(date_field,'dd, yyyy') from ...
or
select to_char(date_field,'mon dd, yyyy') from ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With