Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created January 2, 2018 16:19
Show Gist options
  • Select an option

  • Save codenamejason/af076d6a0e9b6a626df5f41ad3d6aac7 to your computer and use it in GitHub Desktop.

Select an option

Save codenamejason/af076d6a0e9b6a626df5f41ad3d6aac7 to your computer and use it in GitHub Desktop.
CREATE FUNCTION Int2Time(@Time varchar(10), @amPM char(1))
-- returns a dateTime value for the date and time specified.
-- expects a 'numeric' value for time...will excuse any characters
RETURNS SMALLDATETIME
AS
BEGIN
DECLARE @vTime AS VARCHAR(4), @Hour AS VARCHAR(2), @Minute AS VARCHAR(2)
SET @vTime = RIGHT('0'+CAST(dbo.Digits(@Time) AS VARCHAR(4)),4)
SET @Hour = SUBSTRING(@vTime, 1, 2)
if @amPM = 'P' and @Hour < 12
set @Hour = @Hour + 12
SET @Minute = SUBSTRING(@vTime, 3, 2)
RETURN DATEADD(ss,(@Hour*3600)+(@Minute*60), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment