Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How te get only the DATE part

Author  Topic 

zurbum
Yak Posting Veteran

55 Posts

Posted - 2004-11-12 : 16:14:39
I have a table with a datetime value.
Let say it is '8.7.2004 7:53:59'

How can I get only the date part '8.7.2004', coz i need something like

SELECT * FROM TABLE_A WHERE TAB_DATE<='8.7.2004'

which doesn't return records on '8.7.2004'with time>0:00:00. A solution would be to add 1 day, but Iam wondering if there is a function which return only the DATE part?

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-11-12 : 16:21:13
try:


Select * from table_A where dateadd(dy,datediff(dy,0,tab_date),0) <='8.7.2004'


Corey
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-12 : 18:38:21
where tab_date < dateadd(dd,1,'20040708')
To allow it to use indexes/statistics on table_date.
You could also use
where convert(varchar(8),tab_date,112) <= '20040708'

Note the use of yyyymmdd for a character date as this is unambiguous.



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

zurbum
Yak Posting Veteran

55 Posts

Posted - 2004-11-13 : 07:36:42
Works, thanx to both of you.
Go to Top of Page
   

- Advertisement -