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 2005 Forums
 Transact-SQL (2005)
 How to ignore Time Part from Datetime field in Qry

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-10-18 : 00:34:57
Hello All,
I have a Datetime field in my Database. When I store Current Date by GetDate() function, date and time are stored in field.

I have no issue with this datetime but When I use this field in my Where Clause, it does not give me the result.

Like if I write Query Like This

Select * from Employee Where JoiningDate=GetDate()

this will not return any row even if there are few employees who have joined today.

Can any one tell me that how can I ignore the Time part from Date Time field in Where Caluse

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 00:39:31
use this to get employees joined today

Select * from Employee Where JoiningDate>DATEADD(dd,DATEDIFF(dd,0,GetDate()),0)
Go to Top of Page

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-10-18 : 00:43:23
Thanks Alot
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-18 : 00:45:35
quote:
Originally posted by khufiamalik

Thanks Alot


welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-18 : 03:15:56
quote:
Originally posted by visakh16

use this to get employees joined today

Select * from Employee Where JoiningDate>DATEADD(dd,DATEDIFF(dd,0,GetDate()),0)


Select * from Employee
Where JoiningDate>=DATEADD(dd,DATEDIFF(dd,0,GetDate()),0) AND
JoiningDate<DATEADD(dd,DATEDIFF(dd,0,GetDate()),1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -