I am learning SQL Server and am stuck at this conversion issue. Any help is greatly appreciated.
I have a table in SQL Server 2014 with a column Year_Month_Snap
which has data in the nvarchar
datatype.
I need to obtain the last day and hour of the monthend for 35 consecutive months from 2016 jan.
I see there are many suggestions to snap the fixed day to the YYYY-MM part to make it as YYYY-MM-DD part and convert it to date & datetime, but since the last date of every month varies every month (it may be 30 days month or 31 days or 28/29 days February month) so I need to calculate the last date and hour of the given month from the YYYY-MM nvarchar
datatype in the Year_Month_Snap
column.
When I try to convert it to the date/datetime, it throws the following error:
Msg 241, Level 16, State 1, Line 25
Conversion failed when converting date and/or time from character string.
Year_Month_Snap column
Any help is greatly appreciated!!