Skip to content

Instantly share code, notes, and snippets.

@clintmjohnson
Created June 1, 2015 21:09
Show Gist options
  • Select an option

  • Save clintmjohnson/c992ab4f21602cf3a15f to your computer and use it in GitHub Desktop.

Select an option

Save clintmjohnson/c992ab4f21602cf3a15f to your computer and use it in GitHub Desktop.
Convert MMDDYYYY to SQL Server Date Type Function
CREATE FUNCTION [dbo].[MMDDYYYY_TO_SQL_DATE]
(
@MMDDYYYY char(8)
)
RETURNS date
AS
BEGIN
DECLARE @date_out date
SET @date_out = CAST(RIGHT(@MMDDYYYY,4)+'-'+LEFT(@MMDDYYYY,2)+'-'+SUBSTRING(@MMDDYYYY,3,2) as date)
RETURN @date_out
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment