{"id":84,"date":"2010-03-31T22:38:37","date_gmt":"2010-03-31T22:38:37","guid":{"rendered":"http:\/\/jcrawfor74.wordpress.com\/?p=84"},"modified":"2024-07-31T01:10:04","modified_gmt":"2024-07-30T15:10:04","slug":"sql-server-date-format-convert-to-varchar","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2010\/03\/31\/sql-server-date-format-convert-to-varchar\/","title":{"rendered":"SQL Server Date Format  &#8211; Convert to varchar"},"content":{"rendered":"<div id=\"ntsbl-1093368195\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>\n<p>Below is a nice little script to output the various formats displayed by sql server when using convert(varchar, getdate(), n).<\/p>\n\n\n\n<p>It just outputs the current date in the various formats so you can quickly find the one your after<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql line-numbers\">Declare @date datetime\nDeclare @i int\nset @date = getdate()\nset @i = 1\n\nwhile(@i &lt;= 31)\nbegin\n\tif(@i not in (15, 16, 17, 18, 19, 22, 23, 24, 25, 28, 29))\n\tbegin\n\t\tif @i &lt; 22\n\t\t\tprint convert(varchar, @i) + ': ' + convert(varchar, @date, @i)\n\t\tprint convert(varchar, @i+100) + ': ' + convert(varchar, @date, @i+100)\n\tend\n\tset @i = @i + 1\nend<\/code><\/pre>\n\n\n\n<p>Hope it helps<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below is a nice little script to output the various formats displayed by sql server when using convert(varchar, getdate(), n). It just outputs the current [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}