The 'minus' sign that you use before the second 'DayOfYear' is not a proper minus sign. This is causing the error.
BTW you don't need that function. Substracting two dates will give you the number of days and you will not have to deal with the event that the two dates fall in different years.
but make sure that the dates have been entered into fields of type date, not text. This should also eliminate any need to confirm that the dates are valid in your calculation, but you may need to add some details to handle what result you want to see when the second date field is empty.
hbrendelhank you for that, it is much appreciated