{"id":46316,"date":"2019-04-01T13:00:45","date_gmt":"2019-04-01T13:00:45","guid":{"rendered":"https:\/\/www.sqlshack.com\/?p=46316"},"modified":"2019-11-28T11:33:52","modified_gmt":"2019-11-28T11:33:52","slug":"sql-convert-date","status":"publish","type":"post","link":"https:\/\/www.sqlshack.com\/sql-convert-date\/","title":{"rendered":"SQL convert date"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>\n  A common task for newbies is to learn how to do a SQL convert date and work to convert them date to other data types or covert other data types to Date.\n<\/p>\n<p><!--more--><\/p>\n<p>\n  Here in this article we will explain how to work and convert dates to different formats or vice versa.\n<\/p>\n<h2>Requirements<\/h2>\n<ol>\n<li>\n  SQL Server installed. Starting in SQL Server 2008\n<\/li>\n<\/ol>\n<h2>Example<\/h2>\n<p>\n  The first example will be simple, we have a varchar column with a date in a table, but we need to convert the varchar to date. We need to do a SQL convert date.\n<\/p>\n<p>\n  Here it is script to create the table with data:\n<\/p>\n<pre class=\"lang:tsql\">CREATE TABLE [dbo].[delivers](\r\n  [productid] [tinyint] NOT NULL,\r\n  [date] [nvarchar](100) NULL,\r\n CONSTRAINT [PK_delivers] PRIMARY KEY CLUSTERED \r\n(\r\n  [productid] ASC\r\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\r\n) ON [PRIMARY]\r\nGO\r\nINSERT [dbo].[delivers] ([productid], [date]) VALUES (1, N'02-03-2005')\r\nINSERT [dbo].[delivers] ([productid], [date]) VALUES (2, N'03-05-2006')\r\nINSERT [dbo].[delivers] ([productid], [date]) VALUES (3, N'04-05-2011')<\/pre>\n<\/p>\n<p>\n  We want to convert the column date from nvarchar(100) to a date.\n<\/p>\n<p>\n  To do it, we are going to try to modify the design of the table:\n<\/p>\n<p>\n  <img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2019\/04\/ssms-design-table.png\" alt=\"SSMS Design table\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"\/wp-content\/uploads\/2019\/04\/ssms-design-table.png\" alt=\"SSMS Design table\" \/><\/noscript>\n<\/p>\n<p>\n  We will try to change the Data Type to smalldatetime:\n<\/p>\n<p>\n  <img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2019\/04\/change-varchar-to-smalldatime-in-ssms.png\" alt=\"change varchar to smalldatime in SSMS\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"\/wp-content\/uploads\/2019\/04\/change-varchar-to-smalldatime-in-ssms.png\" alt=\"change varchar to smalldatime in SSMS\" \/><\/noscript>\n<\/p>\n<p>\n  You will receive the following error message:\n<\/p>\n<p><strong>Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can\u2019t be re-created or enabled the option Prevent saving changes that require the table to be re-created.<\/strong>\n<\/p>\n<p>\n  To solve this error, in SSMS go to <strong>Tools<\/strong> &gt; <strong>Options<\/strong> menu:\n<\/p>\n<p>\n  <img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2019\/04\/change-options-in-ssms.png\" alt=\"Change Options in SSMS\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"\/wp-content\/uploads\/2019\/04\/change-options-in-ssms.png\" alt=\"Change Options in SSMS\" \/><\/noscript>\n<\/p>\n<p>\n  In Options, go to <strong>Designers &gt;Table and Database Designers<\/strong> and uncheck the Prevent saving changes that require table re-creation:\n  <\/p>\n<p>\n  <img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png\" alt=\"Uncheck Prevent saving changes that require table re-creation\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png\" alt=\"Uncheck Prevent saving changes that require table re-creation\" \/><\/noscript>\n<\/p>\n<p>\n  This option will disable to option to prevent saving table recreation. When you modify the column data type, it requires table re-creation.\n<\/p>\n<p>\n  Now, you can save the design and your table will be converted to date and the SQL convert date is completed:\n<\/p>\n<p>\n  <img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"\/wp-content\/uploads\/2019\/04\/sql-convert-date-date-time-results-after-convert.png\" alt=\"SQL convert date: Date time results after convert sql date\" \/><noscript><img decoding=\"async\" style=\"margin: 0px auto; display: block;\" src=\"\/wp-content\/uploads\/2019\/04\/sql-convert-date-date-time-results-after-convert.png\" alt=\"SQL convert date: Date time results after convert sql date\" \/><\/noscript>\n<\/p>\n<h2>Conversion functions<\/h2>\n<p>\n  T-SQL contains functions to convert data types. We will use CAST and CONVERT to do a SQL convert date.\n<\/p>\n<p>\n  Let\u2019s start with CAST first:\n<\/p>\n<h2>How to convert from varchar, nvarchar, char, nchar to sql date using CAST<\/h2>\n<p>\n  The following example, will show how to convert characters to a datetime date type using the CAST function:\n<\/p>\n<p><pre class=\"lang:tsql\">declare @vardate varchar(100)='03-04-2016'\r\nselect CAST(@vardate AS datetime) AS dataconverted;<\/pre>\n<\/p>\n<p>\n  The example declares a variable named vardate and then this variable that is a varchar is converted to datetime using the CAST function.\n<\/p>\n<p style=\"padding-left:25px;\"><strong><em>Note:<\/em><\/strong><em> For more information about the CAST function, refer to this link: <\/em><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/functions\/cast-and-convert-transact-sql?view=sql-server-2017\" target=\"_blank\" rel=\"nofollow\"><em>CAST and CONVERT (Transact-SQL)<\/em><\/a>\n<\/p>\n<h2>How to do a SQL convert date from varchar, nvarchar, char, nchar to date using CONVERT<\/h2>\n<p>\n  CONVERT is a function that can do the same than CAST in the previous scenario.\n<\/p>\n<p><pre class=\"lang:tsql\">declare @vardate varchar(100)='03-04-2016'\r\nselect CONVERT(datetime, @vardate) as dataconverted<\/pre>\n<\/p>\n<p>\n  The T-SQL code is doing the same than cast, but it is using the CONVERT function. The advantage of CONVERT is that you can easily change the format of the date using the style argument.\n<\/p>\n<p>\n  For example, if you want the date in the ISO format, you can use the following T-SQL sentence:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 121) as isoformat<\/pre>\n<\/p>\n<h2>How to convert sql date into different formats in T-SQL<\/h2>\n<p>\n  The following example shows how to convert the date format in different formats.\n<\/p>\n<p>\n  For Japananes format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 111) as Japanformat<\/pre>\n<\/p>\n<p>\n  For USA format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 110) as USAformat<\/pre>\n<\/p>\n<p>\n  For ANSI format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 102) as ANSIformat<\/pre>\n<\/p>\n<p>\n  For British format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 103) as Britishformat<\/pre>\n<\/p>\n<p>\n  For German format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 104) as Germanformat<\/pre>\n<\/p>\n<p>\n  For Italian format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 105) as Italianformat<\/pre>\n<\/p>\n<p>\n  For European default format:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 113) as EuropeDefaultformat<\/pre>\n<\/p>\n<p>\n  For ODBC Canonical:\n<\/p>\n<p><pre class=\"lang:tsql\">select CONVERT(nvarchar(30),getdate(), 120) as ODBCCanonicalformat<\/pre>\n<\/p>\n<p>\n  You always have the option to use the FORMAT function to get the date in the format that you want:\n<\/p>\n<p><pre class=\"lang:tsql\">SELECT FORMAT( getdate(), 'dd\/MM\/yy')<\/pre>\n<\/p>\n<p>\n  FORMAT is easier to handle dates and use the format of your preference, because you do not need to know the style. However, in my experience I see a lot of code using the CAST and CONVERT functions so, it is better to know them.\n<\/p>\n<p style=\"padding-left:25px;\"><strong><em>Note:<\/em><\/strong><em> For more information about the FORMAT function, refer to this link: <\/em><a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/functions\/format-transact-sql?view=sql-server-2017\" target=\"_blank\" rel=\"nofollow\"><em>FORMAT (Transact-SQL)<\/em><\/a>\n<\/p>\n<h2>Problems related to SQL convert date operations<\/h2>\n<p>\n  When you try to convert to date it is not always possible. The following example shows a common error:\n<\/p>\n<p><pre class=\"lang:tsql\">declare @vardate varchar(100)='11242016'\r\nselect CONVERT(datetime, @vardate) as dataconverted<\/pre>\n<\/p>\n<p>\n  The error message is the following:\n<\/p>\n<p><span style=\"font-family: Courier New;\">Msg 242, Level 16, State 3, Line 22<\/span>\n<\/p>\n<p><strong>The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.<\/strong>\n<\/p>\n<p>\n  You need separators for the date like a \u201c\/\u201d, a \u201c.\u201d or a \u201c-\u201c.\n<\/p>\n<p>\n  The following example, modifies the string from 11242016 to 11-24-2016 and then converts to sql date:\n<\/p>\n<p><pre class=\"lang:tsql\">declare @vardate varchar(100)='11242016'\r\n\r\nset @vardate= SUBSTRING(@vardate, 1, 2)+'-'+ SUBSTRING(@vardate, 3, 2)+'-'+SUBSTRING(@vardate, 5, 4)\r\n\r\nselect CONVERT(date, @vardate) as dataconverted<\/pre>\n<\/p>\n<p>\n  We use substring to concatenate the \u201c-\u201d to use an acceptable date format and then we use the CONVERT function to convert the characters to sql date.\n<\/p>\n<h2>Date data types<\/h2>\n<p>\n  In SQL Server, there are several types of date datatypes:\n<\/p>\n<ul>\n<li>\n    Time returns the hours, minutes, seconds and nanoseconds (hh:mm:ss.nnnnnn)\n  <\/li>\n<li>\n    Date returns the year, months and days (yyyy-mm-dd)\n  <\/li>\n<li>\n    Datetime returns data with this format: YYYY-MM-DD hh:mm:ss[.nnn]\n  <\/li>\n<li>\n    Smalldatetime returns date with this format: YYYY-MM-DD hh:mm:ss\n  <\/li>\n<li>\n    Datetime2 is similar to Datetime, but it has more precision (YYYY-MM-DD hh:mm:ss[.nnnnnnn])\n  <\/li>\n<li>\n     Datetimeoffset it has the precision of datetime2, but it is used for time zones in UTC\n  <\/li>\n<\/ul>\n<h2>SQL convert date to integer<\/h2>\n<p>\n  If you use the CONVERT or CAST to convert a datetime to integer, it will return the number of days since 1900 until the date provided.\n<\/p>\n<p>\n  For example, the following T-SQL code will show the number of days from 1900 until today:\n<\/p>\n<p><pre class=\"lang:tsql\">SELECT CONVERT(INT, GETDATE())<\/pre>\n<\/p>\n<p>\n  You can also convert to integer the year, months, days, etc. of a datetime value. The following code shows how to store in integer variables the day, month and year of a datetime value:\n<\/p>\n<p><pre class=\"lang:tsql\">declare @year int = year(getdate())\r\n \r\ndeclare @month int = month(getdate())\r\ndeclare @day int = day(getdate())\r\nselect @year as year,@month as month,@day as day<\/pre>\n<\/p>\n<h2>Common Questions about SQL convert date in SQL Server<\/h2>\n<p style=\"padding-left:25px;\"><strong><em>Note:<\/em><\/strong><em> The following link contains FAQ about functions and dates in SQL Server: <\/em><a href=\"\/faq-dates-sql-server\/\"><em>FAQ about Dates in SQL Server<\/em><\/a>\n<\/p>\n<h2>Conclusions<\/h2>\n<p>\n  In this article, we learned how to do a SQL convert date in SQL Server. We learned how to modify the data type in a table, how to use the CAST, CONVERT and FORMAT functions. We also learned about the different types of SQL data types.\n<\/p>\n<div id=\"see_more\"><\/div>\n<p><script>\ndisplay_see_more(text='refactor', video='refactor', banner='refactor_b', banner_link='refactor_b');\n<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Introduction A common task for newbies is to learn how to do a SQL convert date and work to convert them date to other data types or covert other data types to Date.<!-- AddThis Advanced Settings generic via filter on wp_trim_excerpt --><!-- AddThis Share Buttons generic via filter on wp_trim_excerpt --><\/p>\n","protected":false},"author":27,"featured_media":46321,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[194],"tags":[],"class_list":["post-46316","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-t-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL convert date<\/title>\n<meta name=\"description\" content=\"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlshack.com\/sql-convert-date\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL convert date\" \/>\n<meta property=\"og:description\" content=\"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlshack.com\/sql-convert-date\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Shack - articles about database auditing, server performance, data recovery, and more\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-01T13:00:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-28T11:33:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png\" \/>\n\t<meta property=\"og:image:width\" content=\"744\" \/>\n\t<meta property=\"og:image:height\" content=\"434\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Daniel Calbimonte\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Calbimonte\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/\"},\"author\":{\"name\":\"Daniel Calbimonte\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/person\\\/8f160d50de307ead1db1ddfc9459754a\"},\"headline\":\"SQL convert date\",\"datePublished\":\"2019-04-01T13:00:45+00:00\",\"dateModified\":\"2019-11-28T11:33:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/\"},\"wordCount\":929,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/uncheck-prevent-saving-changes-that-require-table.png\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/\",\"name\":\"SQL convert date\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/uncheck-prevent-saving-changes-that-require-table.png\",\"datePublished\":\"2019-04-01T13:00:45+00:00\",\"dateModified\":\"2019-11-28T11:33:52+00:00\",\"description\":\"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/sql-convert-date\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/uncheck-prevent-saving-changes-that-require-table.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/04\\\/uncheck-prevent-saving-changes-that-require-table.png\",\"width\":744,\"height\":434,\"caption\":\"Uncheck Prevent saving changes that require table re-creation\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/\",\"name\":\"SQL Shack - articles about database auditing, server performance, data recovery, and more\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlshack.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#organization\",\"name\":\"SQL Shack\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/sqlshack-default.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlshack.com\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/sqlshack-default.png\",\"width\":1200,\"height\":630,\"caption\":\"SQL Shack\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sqlshack.com\\\/#\\\/schema\\\/person\\\/8f160d50de307ead1db1ddfc9459754a\",\"name\":\"Daniel Calbimonte\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g\",\"caption\":\"Daniel Calbimonte\"},\"description\":\"Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 13 years of experience working with different databases. He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs. He writes SQL Server training materials for certification exams. He also helps with translating SQLShack articles to Spanish View all posts by Daniel Calbimonte\",\"url\":\"https:\\\/\\\/www.sqlshack.com\\\/author\\\/daniel-calbimonte\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL convert date","description":"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlshack.com\/sql-convert-date\/","og_locale":"en_US","og_type":"article","og_title":"SQL convert date","og_description":"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.","og_url":"https:\/\/www.sqlshack.com\/sql-convert-date\/","og_site_name":"SQL Shack - articles about database auditing, server performance, data recovery, and more","article_published_time":"2019-04-01T13:00:45+00:00","article_modified_time":"2019-11-28T11:33:52+00:00","og_image":[{"width":744,"height":434,"url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png","type":"image\/png"}],"author":"Daniel Calbimonte","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Daniel Calbimonte","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/#article","isPartOf":{"@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/"},"author":{"name":"Daniel Calbimonte","@id":"https:\/\/www.sqlshack.com\/#\/schema\/person\/8f160d50de307ead1db1ddfc9459754a"},"headline":"SQL convert date","datePublished":"2019-04-01T13:00:45+00:00","dateModified":"2019-11-28T11:33:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/"},"wordCount":929,"commentCount":0,"publisher":{"@id":"https:\/\/www.sqlshack.com\/#organization"},"image":{"@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png","articleSection":["T-SQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/","url":"https:\/\/www.sqlshack.com\/sql-convert-date\/","name":"SQL convert date","isPartOf":{"@id":"https:\/\/www.sqlshack.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png","datePublished":"2019-04-01T13:00:45+00:00","dateModified":"2019-11-28T11:33:52+00:00","description":"Here in this article we will explain step by step how to work and convert dates to different formats or vice versa in SQL Server.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlshack.com\/sql-convert-date\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlshack.com\/sql-convert-date\/#primaryimage","url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png","contentUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/04\/uncheck-prevent-saving-changes-that-require-table.png","width":744,"height":434,"caption":"Uncheck Prevent saving changes that require table re-creation"},{"@type":"WebSite","@id":"https:\/\/www.sqlshack.com\/#website","url":"https:\/\/www.sqlshack.com\/","name":"SQL Shack - articles about database auditing, server performance, data recovery, and more","description":"","publisher":{"@id":"https:\/\/www.sqlshack.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlshack.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.sqlshack.com\/#organization","name":"SQL Shack","url":"https:\/\/www.sqlshack.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlshack.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/03\/sqlshack-default.png","contentUrl":"https:\/\/www.sqlshack.com\/wp-content\/uploads\/2019\/03\/sqlshack-default.png","width":1200,"height":630,"caption":"SQL Shack"},"image":{"@id":"https:\/\/www.sqlshack.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.sqlshack.com\/#\/schema\/person\/8f160d50de307ead1db1ddfc9459754a","name":"Daniel Calbimonte","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/05582c47f23413f6f92f3bd01cd5a06860b3d4f12fe03a0d6e8dc79070931624?s=96&d=mm&r=g","caption":"Daniel Calbimonte"},"description":"Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 13 years of experience working with different databases. He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs. He writes SQL Server training materials for certification exams. He also helps with translating SQLShack articles to Spanish View all posts by Daniel Calbimonte","url":"https:\/\/www.sqlshack.com\/author\/daniel-calbimonte\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/46316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/comments?post=46316"}],"version-history":[{"count":11,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/46316\/revisions"}],"predecessor-version":[{"id":46344,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/posts\/46316\/revisions\/46344"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/media\/46321"}],"wp:attachment":[{"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/media?parent=46316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/categories?post=46316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlshack.com\/wp-json\/wp\/v2\/tags?post=46316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}