0

I am trying to find out what kind of results that I can expect when I run the following sql select statement. InvoiceDate is a smalldatetime data type in the database.

select Cast(InvoiceDate as real) as [cast realDate]
from Invoices

For a date of Jul 30, 2008 I get a result of 39657 For a date of Aug 02, 2008 I get a result of 39660

I can't find any information what kind of result this statement might return and we haven't gone over it in class. Please let me know if I am on the right track.

Thanks

ScottT
  • 41
  • 1
  • 8
  • You get the number of days since some date. You can calculate what it is exactly by subtracting the resulting number from one of the dates. Or, you can look up in the documentation to learn about SQL Server date formats. As a student, you should learn both these methods. – Gordon Linoff Mar 01 '14 at 12:51
  • Gordon, so my statement would return a different result tomorrow? Is my statement implicitly using getdate() and using todays date? Is my result what you might expect to see using my select statement? I have looked high and low for examples for this cast, but can't find anything. It has been 2040 days since July 30, 2008, so my result isn't that. – ScottT Mar 01 '14 at 13:06
  • shf301, not a duplicate. I want to Cast instead of Convert. – ScottT Mar 01 '14 at 13:07
  • @ScottT . . . Your statement will return the same value tomorrow. If you used `getdate()`, you would get a different value. – Gordon Linoff Mar 01 '14 at 13:09
  • 1
    @Gordon Thanks, I see that my answer is the difference between the first date available (01/01/1900) in smalldatetime and the July 30, 2008 date. – ScottT Mar 01 '14 at 13:15

0 Answers0