--:SetVar Function "AUX:CompareDates"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:CompareDates' )
   drop function [AUX:CompareDates]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:CompareDates]( @Date_1 datetime2, @Date_2 datetime2 )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE COMPARISON, WITH ROUNDING TO “YMD” (VIA TRUNCATION OF TIME PARTS):
#
# Comparison result
# :   -1 —— 1st YMD is lesser than 2nd YMD;
# :    1 —— 1st YMD is greater than 2nd YMD;
# :    0 —— 1st YMD is equal to 2nd YMD;
# : null —— correlation is undetermined (at least one argument is null)
#
# === Usage: ===
# dbo.[AUX:CompareDates]( <Date-1>, <Date-2> )
#
==================================================================================================*/

if @Date_1 is null or @Date_2 is null return null

----------------------------------------------------------------------------------------------------

if DAY  ( @Date_1 ) = DAY  ( @Date_2 ) and
   MONTH( @Date_1 ) = MONTH( @Date_2 ) and
   YEAR ( @Date_1 ) = YEAR ( @Date_2 )
   return 0

return
   case
      when @Date_1 < @Date_2
      then -1 else 1
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:CompareDates](
   CONVERT(datetime2,'11/17/2015',101),
   CONVERT(datetime2,'11/19/2015',101) ) 'Date comparison result'
*/
