Solved

Calculating Last day of the current month

Posted on 2015-02-02
2
110 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 17

Accepted Solution

by:
John Gates earned 300 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 48

Assisted Solution

by:PortletPaul
PortletPaul earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

697 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