+ Post New Thread
Results 1 to 2 of 2
Coding Thread, SQL DATEPART/GETDATE Filtering in Coding and Web Development; Hi all. I am trying to use the DATEPART function on GETDATE() in the WHERE clause. I need to only ...
  1. #1
    Shrimpersfan's Avatar
    Join Date
    Feb 2008
    Location
    Peterborough
    Posts
    52
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    SQL DATEPART/GETDATE Filtering

    Hi all.

    I am trying to use the DATEPART function on GETDATE() in the WHERE clause. I need to only show the results if GETDATE's month is not in December or January.

    Any ideas?

    Cheers

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,159
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    125
    Code:
    select * from jobs where datepart(m,logdate)=12
    gets you december only

    Code:
    select * from jobs where datepart(m,logdate)=12 or datepart(m,logdate)=1
    gets you January and December.

    Getting "not January and not December" is just a case of negating that -

    Code:
    select * from jobs where not(datepart(m,logdate)=12)  and not(datepart(m,logdate)=1)
    although because we "know" something about months you can simplify it to:
    Code:
    select * from jobs where datepart(m,logdate) between 2 and 12



SHARE:
+ Post New Thread

Similar Threads

  1. Synetrix filtering
    By vsnider in forum London Grid for Learning (LGfL)
    Replies: 13
    Last Post: 23rd October 2009, 02:11 PM
  2. Exchange Filtering
    By gibbo_ap in forum How do you do....it?
    Replies: 5
    Last Post: 29th January 2009, 05:44 PM
  3. MS SQL 2005 - Dump SQL
    By tom_newton in forum Windows
    Replies: 7
    Last Post: 23rd January 2008, 06:10 PM
  4. Content filtering
    By mitcheln in forum School ICT Policies
    Replies: 11
    Last Post: 20th December 2006, 09:38 PM
  5. Web Filtering
    By SpuffMonkey in forum How do you do....it?
    Replies: 20
    Last Post: 17th May 2006, 10:10 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •