Save datetime in mssql 2005 without hours, minutes and seconds

I want to save my dates in sql2005 as dates (without hour minutes and seconds). I want to do this because the function between the functions is not always correct if the hours, minutes and seconds are full.

but neither datetime nor smalldatetime allow this, in 2008 you have a Date column that can do this.

I also found this question that helps me, but I don’t like casting to fulfill my queries: How to remove the temporary part of a datetime value (SQL Server)?

+3
source share
8 answers

Necasting:

SET @d = DATEADD(dd, 0, DATEDIFF(dd, 0, @dt))

0 0, .

, CAST. 0 , .

+7
SELECT CONVERT (date, GETDATE()) -- Without hours, minutes and seconds.

. http://msdn.microsoft.com/en-us/library/ms188383.aspx

+1

, , , . , - -, , .

+1

, . , .

0

.NET,

DateTime.Now.Date

datetime.

0

BETWEEN , datetime , 00: 00: 00.000, BETWEENS, .

,

DECLARE @FilterDate datetime
SET @FilterDate='3/18/2009'

QUERY
    ...
    WHERE Column1 >= @FilterDate AND Column1 < @FilterDate + 1

DECLARE @StartFilterDate datetime
DECLARE @EndFilterDate datetime
SET @StartFilterDate ='3/18/2009'
SET @EndFilterDate ='3/30/2009'

QUERY
    ...
    WHERE Column1 >= @StartFilterDate AND Column1 < @EndFilterDate + 1
0
SELECT CONVERT(DATETIME, CONVERT(DATE, GETDATE()))
0

, :

select DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))
0

Source: https://habr.com/ru/post/1705453/


All Articles