1

I have a table with a list of clients, with a column that shows the date their accounts were created. I want to make the last day of this date. I tried using the EOMONTH function, but it does not work.

For instance, if client 1 came on January 6th, and client 2 came on February 6th of this year, I want it to show 31-01-2018 and 28-02-2018.

Any ideas?

Thanks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sabina
  • 11
  • 1

1 Answers1

0

Gordon is right, I have tried EOMONTH for your given data and it returns perfect value look at below, in second parameter you have to pass value as per requirement if you pass value as 1 it will give you last date of next month i.e Jan+1=Feb

 DECLARE @myDate Datetime='06-Jan-2018'
 SELECT EOMONTH(@myDate,0) AS MyDate

If your version not support the EOMONTH function then try below query:

 SELECT CAST(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@myDate)+1,0)) AS DATE)

Output:

enter image description here