Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calculating Last day of the current month

Posted on 2015-02-02
2
Medium Priority
?
114 Views
Last Modified: 2015-02-02
I have the following code to calculate the last day of the current month.
The output is correct, but it is also displaying the time.
How can I write the code so it only shows the date and not the time?

DATEADD(D,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
0
Comment
Question by:metalteck
2 Comments
 
LVL 18

Accepted Solution

by:
John Gates, CISSP earned 1200 total points
ID: 40585175
SQL 2008 and greater

SELECT CONVERT(date, DATEADD(D,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)))


Hope this helps!
-D-
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 800 total points
ID: 40585177
To control display of only year-month-day portion use format() if using SQL 2012 or later otherwise use convert()

see: SQL Server Date Styles (formats) using CONVERT()

e.g.

convert(varchar(10), your_data_here ,121)

Note you can control the length of the output by limiting the number of characters
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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