This returns a string from a date or number using the format_string syntax. In the case of a date, the format_string should be structured to indicate the year, month, day, etc. with their initial.
Working with time:
- To remove the time from a date time use the TRUNC function.
- To retrieve the time from a date use format(GETDATE(),'HH:mn:ss')
See also: MONTH, DAYOFWEEK.
Example:
/* might return something like 29-2015-12 /SELECT FORMAT (GETDATE(), 'dd-yyyy-mm') / returns 5,459,40 /SELECT FORMAT (5459.4, '##,##0.00') / Returns name of month in full e.g. 'October' /SELECT DISTINCT thedate,FORMAT(thedate,'MMMMM') AS MonthName FROM transactTheDateMonth10/1/2000October10/2/2000October10/3/2000October10/4/2000October / Returns name of month in abbreviated e.g. Oct */SELECT DISTINCT thedate,FORMAT(thedate,'MMM') AS MonthName FROM transactTheDateMonth10/1/2000Oct10/2/2000Oct10/3/2000Oct10/4/2000Oct