Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filter records by datetime

Status
Not open for further replies.

learner45

Technical User
Jul 31, 2009
16
GB
Hi,

I would like to create a view to filter records from the last 6 months. e.g:

select * from Users

where
loginDATE > DATEADD(MONTH, - 6, GETDATE()) AND
loginDATE < DATEADD(MONTH, 0, GETDATE())

I am getting empty records with this although records do exist in the last 6 months!

The column being used for this purpose has 'datetime' as data type.

Thansk for your assistance!!!!

 
The query above should work. Are you sure you're in the right database?
 
yes the database is correct.

It might sound like a stupid question: 'is it not necessary to add 'year' part in the query?
 
No. You don't need to worry about the year part. Run this:

Select DATEADD(MONTH, - 6, GETDATE())

Notice that this simply takes today's date and time and subtracts 6 months from it. Also... adding 0 months to GetDate() doesn't change the value at all.

Is there anything else in the where clause that may be preventing rows from returning with this query?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top