JULIAN TO DATETIME [줄리안 형식 날짜를 데이트 타임 형식으로 변환]
-- ================================================
-- Template generated from Template Explorer using:
-- Create Scalar Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[JULIAN_TO_DATETIME](@date as int) RETURNS DATETIME
AS
BEGIN
-- 줄리안데이트를 DateTime으로 변환
declare @return as datetime, -- Return Value
@tempyyyy as int, -- Year
@interval as int
-- Year, Month, Day 계산
set @tempyyyy = 2000 + convert(int, @date / 1000)
set @interval = convert(int, right(convert(varchar(6), @date), 3)) - 1
set @return = dateadd(d,@interval,convert(datetime,convert(char(4),@tempyyyy)+'0101',112))
return @return
END
GO
실행
SELECT JULIAN_TO_DATETIME('20135')
값 : 2020-05-14 00:00:00.000