Date Format Functions

Contact Us or call 1-877-932-8228
Date Format Functions

Date Format Functions

The TO_CHAR functions is also available for dates and can support various date format models. Once a date has been converted to a string of characters, it will be sorted differently in an ORDER BY clause.

Some of the most common characters used to specify date format models include MM (two digit month), DD (two digit day), YYYY (four digit year), HH24 (hour using a 24 hour clock), MI (for minute), SS for second. Be careful not to confuse MM (month) and MI (minute).

Code Sample:

	TO_CHAR(hire_date, 'MM/DD/YYYY HH24:MI:SS'),
	TO_CHAR(sysdate, 'MM/DD/YYYY HH24:MI:SS')
FROM employees 
WHERE last_name LIKE 'K%';

This demonstrates a formatting of a date using the hire date in the employee table (which does not have intersting hour, minute and second information) and the formatting of SYSDATE.