Solved

Calculating Last day of the current month

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Oracle Pivot 2 35
query help 18 51
SQL query 4 29
Advice on encrpting some store produces on MS SQL  sql 5 16
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now