<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx</link><description>Reading Erik Porter&amp;#39;s post Separating Date and Time in T-SQL , I remembered I have created some SQL Server 2000 functions which deals with such scenario. I am attaching them just below for readers&amp;#39; appreciation. CREATE FUNCTION dbo.DATEVALUE </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#7225544</link><pubDate>Thu, 08 Oct 2009 14:46:59 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7225544</guid><dc:creator>Muncho</dc:creator><author>Muncho</author><description>&lt;p&gt;You can use cast(... as int) instead of &amp;quot;ROUND&amp;quot;:&lt;/p&gt;
&lt;p&gt;cast(cast(cast(@Time as float) as int) as datetime)&lt;/p&gt;
&lt;p&gt;You can even omit cast(... as datetime) if you are assigning to a &amp;quot;DATETIME&amp;quot; variable or column. This is because you can assign an integer to a datetime and the value is considered the number of days since 1900-01-01.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7225544" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#6535509</link><pubDate>Mon, 18 Aug 2008 19:02:47 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6535509</guid><dc:creator>Michael Bartlett</dc:creator><author>Michael Bartlett</author><description>&lt;p&gt;Great solution! &amp;nbsp;Thanks.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6535509" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#6215270</link><pubDate>Fri, 23 May 2008 22:46:10 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6215270</guid><dc:creator>david</dc:creator><author>david</author><description>&lt;p&gt;If you only need the date part of a datetime variable discarding hours, minutes, seconds a better solution is available here&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ugmfree.it/TipsTsql.aspx?tip=TipTsqlDateTime" rel="nofollow" target="_new"&gt;www.ugmfree.it/TipsTsql.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;DECLARE @Today datetime&lt;/p&gt;
&lt;p&gt;SELECT @Today = CONVERT(varchar,getdate(),112)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6215270" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#126392</link><pubDate>Wed, 05 May 2004 12:44:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:126392</guid><dc:creator>Luciano Evaristo Guerche</dc:creator><author>Luciano Evaristo Guerche</author><description>Dear Denny,&lt;br&gt;&lt;br&gt;I guess the following link may help you somehow:&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://weblogs.asp.net/guerchele/archive/2004/02/10/70767.aspx"&gt;http://weblogs.asp.net/guerchele/archive/2004/02/10/70767.aspx&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=126392" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#125987</link><pubDate>Tue, 04 May 2004 21:31:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:125987</guid><dc:creator>denny</dc:creator><author>denny</author><description>Very slick....&lt;br&gt;&lt;br&gt;somewhere I saw a snipet one time that would take a row of values and make it output as a set of rows...&lt;br&gt;&lt;br&gt;U used that to make a drop-down-combo in html with one sql call to build the whole list.&lt;br&gt;&lt;br&gt;/me wonders if I can find that code now?&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=125987" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#125977</link><pubDate>Tue, 04 May 2004 21:08:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:125977</guid><dc:creator>Luciano Evaristo Guerche</dc:creator><author>Luciano Evaristo Guerche</author><description>Dear Jerry,&lt;br&gt;&lt;br&gt;Thanks for your comments on the code. As you noted on time, ROUND may also TRUNCATE. I guess my code works properly, at least it worked when I tested it last time. Anyway, I am happy there are people out there watching my scarce postings and spending time commenting on it...&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=125977" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#125970</link><pubDate>Tue, 04 May 2004 20:54:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:125970</guid><dc:creator>Jerry Pisk</dc:creator><author>Jerry Pisk</author><description>And I look like an idiot, ROUND(value, 0, 1) will truncate, not ROUND :)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=125970" width="1" height="1"&gt;</description></item><item><title>re: RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#125967</link><pubDate>Tue, 04 May 2004 20:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:125967</guid><dc:creator>Jerry Pisk</dc:creator><author>Jerry Pisk</author><description>Your function do not get the date part of a datetime value. The problem is that you're rounding the value instead of stripping the time value and just keeping the integer part:&lt;br&gt;&lt;br&gt;&lt;br&gt;CREATE FUNCTION [dbo].[up_date_value] (@date datetime) RETURNS datetime AS&lt;br&gt;&lt;br&gt;RETURN CAST(FLOOR(CAST(@date AS float)) AS datetime)&lt;br&gt;&lt;br&gt;&lt;br&gt;Your function will return the next day for values in the afternoon. Mine function would return invalid values for negative dates but SQL server doesn't support those. If it did all we'd have to do is to add an IF there and use CEILING for negative dates.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=125967" width="1" height="1"&gt;</description></item><item><title>RE: Separating Date and Time in T-SQL</title><link>http://weblogs.asp.net/guerchele/archive/2004/05/04/RE_3A00_-Separating-Date-and-Time-in-T_2D00_SQL.aspx#125904</link><pubDate>Tue, 04 May 2004 17:15:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:125904</guid><dc:creator>TrackBack</dc:creator><author>TrackBack</author><description>&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=125904" width="1" height="1"&gt;</description></item></channel></rss>