?
Solved

Calculating Last day of the current month

Posted on 2015-02-02
2
Medium Priority
?
112 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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

765 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