valid_date

mail@pastecode.io avatar
unknown
sqlserver
2 years ago
358 B
4
Indexable
Never
create function is_valid_date(@param_date date, @start_date date, @end_date date)
returns bit 
as begin

declare @date_diff int = DATEDIFF(day, @start_date, @param_date)
	
	if @date_diff < 0
		return 0

	if @end_date is null
		return 1

	set @date_diff = DATEDIFF(day, @end_date, @param_date)

	if @date_diff > 0 
		return 0
	
	return 1
end