Created
August 30, 2015 08:03
-
-
Save malkitsingh/08d115fc964777de2f9c to your computer and use it in GitHub Desktop.
This file contains 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].[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