Getting Current Monthend

Hi all,
Does anyone know how to calculate current monthend date from a date..

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

Thanks!
Micky
MickeyMinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
no problem:
select dateadd(day, -1,dateadd(month, 1,convert(datetime,left('20080429',6) + '01',112)))

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
select dateadd(day, -1,dateadd(month, 1,convert(datetime,convert(varchar(8),  your_date_field , 120) + '01',120)))

Open in new window

0
 
MickeyMinAuthor Commented:
sorry but I think my date is a string '20080429'
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
MickeyMinAuthor Commented:
if I just run this part  select dateadd(day, -1,dateadd(month, 1,'20080429'))

it returns

2008-05-28
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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))

Open in new window

0
 
MickeyMinAuthor Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.