Log in  ::  Register  ::  Not logged in

## DateTime Puzzle

 Author Message Sunil Chandurkar SSC-Addicted Group: General Forum Members Points: 455 Visits: 81 Comments posted to this topic are about the item DateTime Puzzle bitbucket-25253 SSC-Insane Group: General Forum Members Points: 24249 Visits: 25280 Thanks, a nice easy question If everything seems to be going well, you have obviously overlooked something. RonPlease help us, help you -before posting a question please read Before posting a performance problem please read Paul White SSC Guru Group: General Forum Members Points: 54668 Visits: 11391 The explanation could be better. The question does not involve a float value. By default, the literal value 0.25 is interpreted as a numeric(2,2):`SELECT 0.25 AS col1INTO #v;EXECUTE tempdb.sys.sp_columns @table_name = N'#v', @table_owner = N'banana', @table_qualifier = N'tempdb', @column_name = N'col1';DROP TABLE #v;`If the intention has been to show a float, either a float literal or a typed variable could have been used:`SELECT CAST(25e-2 AS datetime);DECLARE @f float = 25e-2;SELECT CAST(@f AS datetime);`Datetime values are no more "associated" with a float value than they are with any other type that can be implicitly converted (see the conversion table in Books Online - CAST and CONVERT (Transact-SQL)). The internal representation is two integers - one for the number of days from the base date, and one for the number of ticks (1/300th second) since midnight. In fact the second format seems to be 0.003 second time intervals, rounded to 0, 3, or 7 in the third decimal place when used:`DECLARE @dt datetime = '1900-01-02 00:00:00.006';SELECT @dt;SELECT CONVERT(binary(8), @dt);`My biggest concern with this question though, is that it encourages people to be sloppy with types and relies on hidden implicit conversions. As a general rule, try to be explicit about types in T-SQL code. Paul WhiteSQLPerformance.comSQLblog.com@SQL_Kiwi Koen Verbeeck SSC Guru Group: General Forum Members Points: 99732 Visits: 13322 Thanks for the question. Easy one to start the week. How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP Hugo Kornelis One Orange Chip Group: General Forum Members Points: 25063 Visits: 12583 Thanks, Paul! You saved me a lot of time by addressing all the points I wanted to address after reading the explanation of this question.It never ceases to amaze me how many people think datetime data is internally stored as a float. That statement is even being made explicitly in the topic referenced in the explanation of this question. And while this question uses the weaker verb "associate", it will again reinforce that believe for some people.And now, I am silently hoping that we'll get the same question tomorrow, with the same answer options - but with data type datetime2. Hugo Kornelis, SQL Server MVPVisit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis Igor Micev SSChampion Group: General Forum Members Points: 14486 Visits: 5176 The answer was easy. I also appreciate the discussion from SQL Kiwi.ThanksIgorMi Igor Micev,My blog: www.igormicev.com Igor Micev SSChampion Group: General Forum Members Points: 14486 Visits: 5176 The answer was easy. I also appreciate the discussion from SQL Kiwi.ThanksIgorMi Igor Micev,My blog: www.igormicev.com Igor Micev SSChampion Group: General Forum Members Points: 14486 Visits: 5176 The answer was easy. I also appreciate the discussion from SQL Kiwi.ThanksIgorMi Igor Micev,My blog: www.igormicev.com Stewart "Arturius" Campbell SSC-Insane Group: General Forum Members Points: 24809 Visits: 7501 Thanks for the simple question.However, as stated by Paul, the idea that DATETIME et al are stored as FLOAT is highly disturbing. ____________________________________________Space, the final frontier? not any more...All limits henceforth are self-imposed.“libera tute vulgaris ex” Paul White SSC Guru Group: General Forum Members Points: 54668 Visits: 11391 Hugo Kornelis (5/7/2012)Thanks, Paul! You saved me a lot of time by addressing all the points I wanted to address after reading the explanation of this question.Makes a change! I normally get to the question after you and end up posting the '+1' :-)I too, look forward to the repeat question based on DATETIME2. Paul WhiteSQLPerformance.comSQLblog.com@SQL_Kiwi

## Permissions

 You can't post new topics. You can't post topic replies. You can't post new polls. You can't post replies to polls. You can't edit your own topics. You can't delete your own topics. You can't edit other topics. You can't delete other topics. You can't edit your own posts. You can't edit other posts. You can't delete your own posts. You can't delete other posts. You can't post events. You can't edit your own events. You can't edit other events. You can't delete your own events. You can't delete other events. You can't send private messages. You can't send emails. You can read topics. You can't vote in polls. You can't upload attachments. You can download attachments. You can't post HTML code. You can't edit HTML code. You can't post IFCode. You can't post JavaScript. You can post emoticons. You can't post or upload images.

##### Select a forum
 SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 14 - Administration      SQL Server 14 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      Question of the Day (QOD)      SQL Server Security Skills Microsoft Access      Microsoft Access Products and Books      Third Party Products         CA         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         SQLCentric         Golden Gate Software         Lumigent         Red Gate Software         Quest Software         ApexSQL         Idera      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 7.0 Books         Discuss SQL Server 2000 Books Notification Services      Administration Article Discussions Future Versions      SQL 12

## Search

 Copyright © 2002-2017 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.