Reputation: 517
I have a column with date like this: mm/yyyy, for istance:
02/2022
12/2099
...
I need to convert them to yyymmgg format, where gg should be last day of that month, can you help me? I can get month and year by left(date, 2) and right(date, 5), how I can find the right day, especially for february?
Upvotes: 0
Views: 95
Reputation: 1269693
You can convert to a date using some string manipulation and convert()
. Then just use eomonth()
:
select eomonth(convert(date, '01/' + mmyyyy, 103))
I would recommend that you leave the value as a date. You can, of course, convert back to a string if that is what you really want.
Upvotes: 2