# SQL Server CONVERT() Function

SQL Server Date Functions

## Definition and Usage

The CONVERT() function is a general function that converts an expression of one data type to another.

The CONVERT() function can be used to display date/time data in different formats.

## Syntax

CONVERT(data_type(length),expression,style)

Value | Description
--- | ---
data_type(length) | Specifies the target data type (with an optional length)
expression | Specifies the value to be converted
style | Specifies the output format for the date/time

The table below represent the style values for datetime or smalldatetime conversion to character data:

Value (century yy) | Value (century yyyy) | Input/Output | Standard
--- | --- | --- | ---
- | 0 or 100 | mon dd yyyy hh:miAM (or PM) | Default
1 | 101 | mm/dd/yy | USA
2 | 102 | yy.mm.dd | ANSI
3 | 103 | dd/mm/yy | British/French
4 | 104 | dd.mm.yy | German
5 | 105 | dd-mm-yy | Italian
6 | 106 | dd mon yy |
7 | 107 | Mon dd, yy |
8 | 108 | hh:mm:ss |
- | 9 or 109 | mon dd yyyy hh:mi:ss:mmmAM (or PM) | Default+millisec
10 | 110 | mm-dd-yy | USA
11 | 111 | yy/mm/dd | Japan
12 | 112 | yymmdd | ISO
- | 13 or 113 | dd mon yyyy hh:mi:ss:mmm (24h) |
14 | 114 | hh:mi:ss:mmm (24h) |
- | 20 or 120 | yyyy-mm-dd hh:mi:ss (24h) |
- | 21 or 121 | yyyy-mm-dd hh:mi:ss.mmm (24h) |
- | 126 | yyyy-mm-ddThh:mi:ss.mmm (no spaces) | ISO8601
- | 130 | dd mon yyyy hh:mi:ss:mmmAM | Hijiri
- | 131 | dd/mm/yy hh:mi:ss:mmmAM | Hijiri

### Example

The following script uses the CONVERT() function to display different formats. We will use the GETDATE() function to get the current date/time:

CONVERT(VARCHAR(19),GETDATE())
CONVERT(VARCHAR(10),GETDATE(),10)
CONVERT(VARCHAR(10),GETDATE(),110)
CONVERT(VARCHAR(11),GETDATE(),6)
CONVERT(VARCHAR(11),GETDATE(),106)
CONVERT(VARCHAR(24),GETDATE(),113)

The result would look something like this:

Nov 04 2011 11:45 PM
11-04-11
11-04-2011
04 Nov 11
04 Nov 2011
04 Nov 2011 11:45:34:243

SQL Server Date Functions

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples