Assuming you're on a sufficiently modern version of MSSQL, this should work:
DECLARE @dt DATETIME = '2021-12-31 00:00:00.000'
SELECT DATETIMEFROMPARTS(
DATEPART(YEAR, @dt),
DATEPART(MONTH, @dt),
DATEPART(DAY, @dt),
23, /* hour */
59, /* minute */
59, /* second */
0 /* fractional seconds*/
);
I'd also be remiss if I didn't mention that by calculating the datetime you've requested, you might be employing an antipattern. If your goal in calculating the above is to do something like:
select *
from dbo.yourTable
where DateCreated >= @StartOfDay
and DateCreated <= @EndOfDay;
You'll eventually have an issue with the above if the DateCreated column admits a value like '2021-12-21 23:59:59.997'.
If that is indeed your goal, it's better to write that query as:
select *
from dbo.yourTable
where DateCreated >= @StartOfDay
and DateCreated < @StartOfNextfDay;
That is use a half-open interval instead of a fully closed interval.