Solved

# Getting Current Monthend

Posted on 2008-06-20
243 Views
Hi all,
Does anyone know how to calculate current monthend date from a date..

so 29-04-2008
returns
30-04-2008

Thanks!
Micky
0
Question by:MickeyMin
[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
• 3
• 3

LVL 143

Expert Comment

ID: 21829580
this should do:
``````select dateadd(day, -1,dateadd(month, 1,convert(datetime,convert(varchar(8),  your_date_field , 120) + '01',120)))
``````
0

Author Comment

ID: 21829606
sorry but I think my date is a string '20080429'
0

Author Comment

ID: 21829612

it returns

2008-05-28
0

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 250 total points
ID: 21829616
no problem:
``````select dateadd(day, -1,dateadd(month, 1,convert(datetime,left('20080429',6) + '01',112)))
``````
0

LVL 143

Expert Comment

ID: 21829619
note: if you want to get a "date range" query to include up to the last day of the month, it should best be something like this, doing a < of the first of next month:
``````select ...
where yourfield < dateadd(month, 1,convert(datetime,left('20080429',6) + '01',112))
``````
0

Author Closing Comment

ID: 31469096
thank you!
0

## Featured Post

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
###### Suggested Courses
Course of the Month2 days, 2 hours left to enroll