Date function use to select record not more than date in month

Posted on 2011-04-27
Last Modified: 2012-06-21
what is the date function I can use to select records which no more than date in the month. For example I run a select statement

select * from recordtable where date <30:04:2011 23:59:59:000'

But using a date function I want when I assign the where clause sql will automatically detect end date for each month.
Question by:motioneye
    LVL 23

    Accepted Solution


    select * from recordtable where date < DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
    LVL 6

    Assisted Solution

    select * from recordtable where GetDate() < '30:04:2011 23:59:59:000'
    LVL 23

    Assisted Solution

    by:Rajkumar Gs
    LVL 32

    Expert Comment

    use this
    declare @LastOfMonth DateTime
    set @LastOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
    elect * from recordtable where date <= LastOfMonth

    Open in new window

    LVL 21

    Assisted Solution

    by:Alpesh Patel
    select * from recordtable where date < dateadd(day,-1,dateadd(month,1,convert(varchar,YEAR(GETDATE())) + '-' + right('0' + convert (varchar,MONTH(GETDATE())),2) + '-01' ))

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now