This Scalar-valued function return a Midas datetime from a real datetime. In midas, the date are the number of day since 1971-12-31.
ALTER FUNCTION [dbo].[udf_DateSqlToMidas] ( @Date datetime ) RETURNS int AS BEGIN RETURN datediff(day, '1971-12-31', @Date) END