Groups | Blog | Home
all groups > sql server mseq > september 2007 >

sql server mseq : Help with Current DATE in Query


SQL Brad
9/10/2007 6:16:00 AM
Hello, I have a table that lists my bank transactions. I have a uniqueid in
the first field and several other fields....one of which is DATE.... now, I
want to run a query where my view is based upon the DATE. however I want to
only show transactions that are the same date as the system date (this is to
see how much work my employees have done). Please see my example below, this
code works....

SELECT transid, [date], description, amt, taxamt
FROM dbo.taxtransactions
WHERE ([date] = '9/9/2007')

However, where it has 9/9/2007, I want it to be TODAYS Date

Russell Fields
9/10/2007 1:15:57 PM
SQL Brad,

There are several ways to get the date only, without time included. This is
one of the best performing since it uses math instead of character string
conversions:

DATEADD(DD,DATEDIFF(DD,'1/1/1753',GetDate()),'1/1/1753') -- Any origin
date will do

Assuming that your DATE columns only have date set (and time set to
00:00:00.000) then this will work for you. If your transactions have date
and time, then:

WHERE DATEADD(DD,DATEDIFF(DD,'1/1/1753',MyDateColumn,'1/1/1753')
= DATEADD(DD,DATEDIFF(DD,'1/1/1753',GetDate()),'1/1/1753')

RLF

[quoted text, click to view]

AddThis Social Bookmark Button