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
 General SQL Server Forums
 New to SQL Server Programming
 Date only Query

Author  Topic 

jtwork
Yak Posting Veteran

82 Posts

Posted - 2007-10-24 : 05:56:05
Ive been trying to pull some data from a table by date and time based on todays date but im having a few probs.

i have managed to convert the datetime to just date but im still stuck.


Here is my query

Select DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) as DL_Date, NONE63 As RAcc, REF_1, CUSTOMER_NAME, NONE5 as DOB
From D.dbo.TORY
Where DL_Date = DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))

i have also tried

Select DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) as DL_Date, NONE63 As RAcc, REF_1, CUSTOMER_NAME, NONE5 as DOB
From D.dbo.TORY
Where DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) = DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))


Please help

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-24 : 06:00:00
[code]Select DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) as DL_Date, NONE63 As RAcc, REF_1, CUSTOMER_NAME, NONE5 as DOB
From D.dbo.TORY
Where DATEADD(dd, DATEDIFF(dd, 0, FILE_DATE_TIME), 0) = DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-24 : 06:01:29
But I prefer using day instead of dd for better clarity

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-24 : 06:38:09
[code]SELECT DATEADD(DAY, 0, DATEDIFF(day, 0, FILE_DATE_TIME)) AS DL_Date,
NONE63 AS RAcc,
REF_1,
CUSTOMER_NAME,
NONE5 AS DOB
FROM D.dbo.TORY
WHERE FILE_DATE_TIME >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) , 0)
AND FILE_DATE_TIME < DATEADD(day, DATEDIFF(day, 0, GETDATE()) + 1, 0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -