SQL Server – Convert() function

Convert () function in SQL Server

Convert () function is used to convert an expression from one data type to another data typeSyntax for CONVERT function
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Convert functions is usually used with date/time data type to convert a date in different formats. Below examples will show the different formats in which we can display the date/time data type using Convert function. In the below examples we use getdate() to get the current date and time of the database server.

select convert(varchar(40), getdate(), 0)

Result:-
Jan 25 2015  9:36PM

select convert(varchar(40), getdate(), 101)

Result:-
01/25/2015

select convert(varchar(40), getdate(), 102)

Result:-
2015.01.25

select convert(varchar(40), getdate(), 103)

Result:-
25/01/2015

select convert(varchar(40), getdate(), 104)

Result:-
25.01.2015

select convert(varchar(40), getdate(), 105)

Result:-
25-01-2015

select convert(varchar(40), getdate(), 106)

Result:-
25 Jan 2015

select convert(varchar(40), getdate(), 107)

Result:-
Jan 25, 2015

select convert(varchar(40), getdate(), 108)

Result:-
21:39:21

select convert(varchar(40), getdate(), 109)

Result:-
Jan 25 2015 10:19:15:583PM


select convert(varchar(40), getdate(), 110)

Result:-
01-25-2015


select convert(varchar(40), getdate(), 111)

Result:-
2015/01/25


select convert(varchar(40), getdate(), 112)

Result:-
20150125


select convert(varchar(40), getdate(), 113)

Result:-
25 Jan 2015 23:22:49:453


select convert(varchar(40), getdate(), 114)

Result:-
23:23:09:970


select convert(varchar(40), getdate(), 120)

Result:-
2015-01-25 23:23:37


select convert(varchar(40), getdate(), 121)

Result:-
2015-01-25 23:24:07.577


select convert(varchar(40), getdate(), 126)

Result:-
2015-01-25T23:24:29.860


select convert(varchar(40), getdate(), 127)

Result:-
2015-01-25T23:24:55.037


select convert(varchar(40), getdate(), 131)

Result:-
5/04/1436 11:25:23:483PM

From the above examples we can see that how we can use the Convert () function to display date time in different formats.

About vivekjohari

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.
This entry was posted in SQL Basic, SQL Functions, SQL Server and tagged , . Bookmark the permalink.

31 Responses to SQL Server – Convert() function

  1. Pingback: constructoras en santo domingo

  2. Pingback: עיתון סקס

  3. Pingback: agencia de viajes en managua

  4. Pingback: https://loveyourselfandeverything.blogspot.com/

  5. Pingback: agencia de viajes en managua

  6. Pingback: real estate for sale in Delaware

  7. Pingback: rhode island roofing

  8. Pingback: ดูบอลสด

  9. Pingback: Rome tour

  10. Pingback: intermittent fasting meal plan

  11. Pingback: Taboo use of sex doll

  12. Pingback: right here

  13. Pingback: Chiropractor in Bronx New York

  14. Pingback: new movie trailers

  15. Pingback: 4d malaysia

  16. Pingback: https://bspsp.edu.pl/

  17. Pingback: agen sbobet terpercaya bonus besar

  18. Pingback: 출장안마

  19. Pingback: google fuck me

  20. Pingback: slot game

  21. Pingback: w88

  22. Pingback: TorSearch onion

  23. Pingback: w88top.com

  24. Pingback: http://szkolenieinteraktywne.pl/naukowa-zabawa-kosmiczne-laboratorium-60253-1195.php

  25. Pingback: buy virtual debit cards

  26. Pingback: led screen

  27. Pingback: Dream Market

  28. Pingback: m88vina

  29. Pingback: character voices

  30. Pingback: Tochka Market

  31. Pingback: Empire Market

Leave a Reply