• About

sqlerrors

~ From the errors of others, a wise man corrects his own

sqlerrors

Tag Archives: end of the month

find last day of the month using EOMONTH

22 Monday Sep 2014

Posted by Praveen D'sa in SQL Server

≈ Leave a comment

Tags

end of the month, EOMONTH, last day of the month

In my previous blog post i have demonstrated how to find first and last date of any month. SQL Server 2012 has introduced a new date function EOMONTH to find the last day of the month.

Syntax
EOMONTH ( start_date [, month_to_add ] )

Arguments
start_date
    Date expression specifying the date for which to return the last day of the month.
month_to_add
    Optional integer expression specifying the number of months to add to start_date.

Examples
EOMONTH without the month_to_add parameter to find last day of current month
EOMONTH - CurrentMonth

EOMONTH with the month_to_add parameter to find last day of last and next month
EOMONTH - last&previousMonths

SQL Server doesn’t provide any function to find start of the month, but we can make use of EOMONTH function to find start date of any month.
EOMONTH - StartofTheMonth

EOMONTH function is available in SQL Server 2012 and higher, for SQL Server 2008 R2 and below you can refer to this blog post.

Advertisement

Share this:

  • More
  • Email
  • Print

Like this:

Like Loading...

Recent Posts

  • What’s wrong with this query? July 30, 2015

Categories

  • Learning (2)
  • MS SQL Tips (3)
  • Performance Tuning (1)
  • SQL Script (5)
  • SQL Server (14)
    • Index (1)
    • Log Shipping (1)
  • SQL Tips & Tricks (1)
  • Uncategorized (5)

Archives

  • July 2015 (2)
  • February 2015 (1)
  • October 2014 (2)
  • September 2014 (1)
  • May 2014 (1)
  • April 2014 (3)
  • March 2014 (2)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (3)
  • November 2013 (9)

sqlerrors

sqlerrors

Disclaimer:

This is my personal blog. The opinions & suggestions expressed here are
my own. For accuracy and official references please refer to MSDN,Microsoft TechNet,
Books Online. I do not endorse any of the tools / applications / books / concepts
mentioned here on my blog. I have simply documented my personal experiences on this
blog.

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • sqlerrors
    • Already have a WordPress.com account? Log in now.
    • sqlerrors
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...
 

    %d bloggers like this: