Explaination
I want to use the functions StartOfWeek and StartOfMonth with the Dateonly function.
I tried to use the DatetimeExtension of DateTime into DateOnly but it does not work and always get errors.
Question
What is the correct way to implement it into DateOnly?
The code
public static class DateTimeExtensions
{
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7;
return dt.AddDays(-1 * diff);
}
public static DateTime StartOfMonth(this DateTime @this)
{
return new DateTime(@this.Year, @this.Month, 1);
}
}
I tried to change DateTime into DateOnly inside the DateTimeExtensions, but without success.