[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Calculating Last day of the current month

Posted on 2015-02-02
2
Medium Priority
?
113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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 …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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