Domanda

Im trying to get the date part of the date column to compare two dates, but could not get date part directly, i tried this Convert(date, getdate()) but this does not work with sql server 2005 as we are using that, and when i tried DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) it gives 2008-09-22 00:00:00.000 where i want only date part without time i-e 00, taken both from the posts: How to return the date part only from a SQL Server datetime datatype

What ihv done is convert(VARCHAR(10),'2014-04-21 00:00:00.000') and it returns 2014-04-21 but it is now in varchar.

Is there some way so that i may get the date part only in date type in sql server 2005.

Thanks in advance.

È stato utile?

Soluzione 2

Is there some way so that i may get the date part only in date type in sql server 2005.

No, the date datatype was added in SQL Server 2008. The best you can do is to use a datetime with the time part 00:00:00.

Altri suggerimenti

Try this, It is for SQL 2008

select Cast(getdate() as Date) as onlyDate

The usual trick to remove the time from datetime is to cast to float and take the int part and cast it back to datetime:

declare @d datetime;
set @d = getdate();
select cast(floor(cast(@d as float)) as datetime);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top