2020. 6. 2. 16:52ㆍIT/MS-SQL
-- ================================================
-- 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
'IT > MS-SQL ' 카테고리의 다른 글
MSSQL 년도, 주차 구하기, DATEPART (0) | 2020.06.18 |
---|---|
DATETIME TO JULIAN [데이트 타임 형식의 날짜를 줄리안 형식으로 변환] (0) | 2020.06.02 |
[MS-SQL] ASCII / CHAR 변환 (0) | 2020.03.18 |
ZPL QR BARCODE (3) | 2020.01.09 |
[MS-SQL] 글자 앞에 문자 또는 숫자 채우기, 1 -> 0001 변환, MS SQL replicate (0) | 2019.09.19 |