João Correia
João Correia

Reputation: 21

t-SQL CAST date returns 2 days less

Can someone explain me why casting a datetime to date returns a 2 days prior date?

I just run into this, and need to understand.

Just execute this:

SELECT 
  CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) AS currDate, 
  CAST(CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) AS DATE) AS lessDays

In my Sql Server 2008 R2 Returns me this:

----------------------------------------------
|          currDate         |    lessDays    |
----------------------------------------------
|   2011-08-28 00:00:00.0   |   2011-08-26   |
----------------------------------------------

Thanks in advance

Upvotes: 2

Views: 733

Answers (1)

Martin Smith
Martin Smith

Reputation: 453288

This is a bug in the JDBC driver not coping with the Date datatype.

A hotfix is available

Upvotes: 1

Related Questions