Skip to content

Instantly share code, notes, and snippets.

@malkitsingh
Created August 30, 2015 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkitsingh/08d115fc964777de2f9c to your computer and use it in GitHub Desktop.
Save malkitsingh/08d115fc964777de2f9c to your computer and use it in GitHub Desktop.
CREATE FUNCTION [dbo].[UNIX_TIMESTAMP] (
@ctimestamp datetime
)
RETURNS integer
AS
BEGIN
/* Function body */
declare @return integer
SELECT @return = DATEDIFF(SECOND,{d '1970-01-01'}, @ctimestamp)
return @return
END
ALTER FUNCTION [dbo].[FROM_UNIXTIME]
(
-- Add the parameters for the function here
@ctimestamp int
)
RETURNS smalldatetime
AS
BEGIN
-- Declare the return variable here
DECLARE @ctimestamp2 smalldatetime
-- Add the T-SQL statements to compute the return value here
select @ctimestamp2 = DateAdd(ss, @ctimestamp, '1970-01-01')
-- Return the result of the function
RETURN @ctimestamp2
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment