Results 1 to 2 of 2

Thread: MSSQL - from today upto end of the month

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    MSSQL - from today upto end of the month

    Hi,

    I currently use the following code to select records of the current month and year.

    Code:
    SELECT * FROM x where  DATEADD(mm,DATEDIFF(mm,0,dateofservice),0)=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
    But now I would only like to show records of the current month but only for current day and future days of the month.
    (ex. assuming tday is 03/13/2013

    TO SHOW
    03/13/2013 ... 03/31/2013

    NOT TO SHOW
    03/01/2013 ... 03/12/2013

    I was wondering if you could give me some tips on how to make this work.

    Thanks

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: MSSQL - from today upto end of the month

    Read this article

    [edit]
    SELECT DATEADD(DD,-DAY(DATEADD(m,1,GETDATE())),DATEADD(m,1,GETDATE()))

    will give you the last day of the month.

    [/edit]
    Last edited by abhijit; Mar 14th, 2013 at 09:47 AM. Reason: query testing
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

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



Click Here to Expand Forum to Full Width