<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sql dateadd Archives - Info Spot</title>
	<atom:link href="https://info-spot.net/tag/sql-dateadd/feed/" rel="self" type="application/rss+xml" />
	<link>https://info-spot.net/tag/sql-dateadd/</link>
	<description>Info Spot blog</description>
	<lastBuildDate>Wed, 04 Dec 2024 07:19:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://info-spot.net/wp-content/uploads/2024/11/cropped-icon-32x32.png</url>
	<title>sql dateadd Archives - Info Spot</title>
	<link>https://info-spot.net/tag/sql-dateadd/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MS SQL Server &#8211; How to get Date only from the datetime value?</title>
		<link>https://info-spot.net/sql-get-date-from-datetime/</link>
					<comments>https://info-spot.net/sql-get-date-from-datetime/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 03 Dec 2024 16:51:51 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[convert date]]></category>
		<category><![CDATA[get date only]]></category>
		<category><![CDATA[sql cast]]></category>
		<category><![CDATA[sql dateadd]]></category>
		<category><![CDATA[sql server]]></category>
		<guid isPermaLink="false">https://info-spot.net/?p=792</guid>

					<description><![CDATA[<p>To get the current date and time: And we have a datetime value: 2024-12-03 18:13:07.271 From the datetime&#8230;</p>
<p>The post <a href="https://info-spot.net/sql-get-date-from-datetime/">MS SQL Server &#8211; How to get Date only from the datetime value?</a> appeared first on <a href="https://info-spot.net">Info Spot</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>To get the current date and time:</p>



<pre class="wp-block-code"><code>SELECT getdate();</code></pre>



<p>And we have a datetime value: 2024-12-03 18:13:07.271</p>



<p>From the datetime value above, you want to extract the date value only. There are several ways to do that:</p>



<ul class="wp-block-list">
<li><strong>Use CONVERT to VARCHAR:</strong></li>
</ul>



<p>CONVERT syntax:</p>



<pre class="wp-block-code"><code>CONVERT ( data_type &#91; ( length ) ] , expression &#91; , style ] )  </code></pre>



<p>In this case, date only, you we are gonna run this query:</p>



<pre class="wp-block-code"><code>SELECT CONVERT(VARCHAR(10), getdate(), 111);</code></pre>



<p>It returns <code>2024/12/03</code> for my test.</p>



<p>The style we used just now is 111, which is yyyy/mm/dd. There are many other style you can choose from. Here are some common types:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Style</th><th>How it’s displayed</th></tr></thead><tbody><tr><td>101</td><td>mm/dd/yyyy</td></tr><tr><td>102</td><td>yyyy.mm.dd</td></tr><tr><td>103</td><td>dd/mm/yyyy</td></tr><tr><td>104</td><td>dd.mm.yyyy</td></tr><tr><td>105</td><td>dd-mm-yyyy</td></tr><tr><td>110</td><td>mm-dd-yyyy</td></tr><tr><td>111</td><td>yyyy/mm/dd</td></tr><tr><td>106</td><td>dd mon yyyy</td></tr><tr><td>107</td><td>Mon dd, yyyy</td></tr></tbody></table></figure>



<p>Because each type generates a different length, so you should define the right varchar length then.</p>



<ul class="wp-block-list">
<li><strong>You can also convert to date:</strong></li>
</ul>



<pre class="wp-block-code"><code>SELECT CONVERT(date, getdate());</code></pre>



<p>It will return the current date value along with starting value for time. For example, the result for my case is:</p>



<pre class="wp-block-code"><code>Dec  3 2024 12:00:00:AM</code></pre>



<p>For older version than SQL Server 2008, you should use this instead:</p>



<pre class="wp-block-code"><code>SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()));</code></pre>



<p>And it returns the same result.</p>



<ul class="wp-block-list">
<li><strong>Use CAST</strong></li>
</ul>



<p>CAST syntax:</p>



<pre class="wp-block-code"><code>CAST ( expression AS data_type &#91; ( length ) ] )  </code></pre>



<p>For the example above, you can use:</p>



<pre class="wp-block-code"><code>SELECT CAST(getdate() AS date);</code></pre>



<p>Or you can cast it to varchar:</p>



<pre class="wp-block-code"><code>SELECT CAST(getdate() AS varchar(10));</code></pre>
<p>The post <a href="https://info-spot.net/sql-get-date-from-datetime/">MS SQL Server &#8211; How to get Date only from the datetime value?</a> appeared first on <a href="https://info-spot.net">Info Spot</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://info-spot.net/sql-get-date-from-datetime/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
