Last active
April 1, 2022 18:02
-
-
Save MarkPryceMaherMSFT/d2cf8675bc74cd592db0f64e7621d0d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create FUNCTION dbo.check_my_date (@value varchar(255)) | |
RETURNS datetime2 | |
as | |
BEGIN | |
declare @rt datetime2; | |
set @rt = convert(datetime2,'19000101') -- default value | |
if @value = '0' -- special case | |
begin | |
set @rt = convert(datetime2,'00010101') | |
end | |
else | |
begin | |
set @rt = try_parse(@value as datetime2) | |
-- logic around dates before a certain date | |
if try_parse(@value as datetime2) < convert(datetime2,'19000101') | |
begin | |
set @rt = convert(datetime2,'19000101') | |
end | |
end | |
return @rt; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment