2020. 6. 2. 16:57ㆍ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].[DATETIME_TO_JULIAN](@date as datetime) returns int
as
begin
-- DataTime 값을 줄리안데이트 형식으로 변환
declare @return as int
, @tempdate as char(8)
, @basedate as datetime
, @tempyyyy as int
, @interval as int
set @tempdate = convert(char(8), @date, 112)
set @tempyyyy = year(@date) -- cast(left(@tempdate, 4) as int)
set @basedate = convert(datetime, left(@tempdate, 4) + '0101', 112)
set @interval = datediff(d, @basedate, @date) + 1
set @return = (@tempyyyy - 2000) * 1000 + @interval
return @return
end
GO
실행
SELECT [dbo].[DATETIME_TO_JULIAN]('20200630')
값 : 20182
'IT > MS-SQL ' 카테고리의 다른 글
[MSSQL] 특정문자 개수 알아오기, 특정문자 위치찾기, 특정문자 찾기 (0) | 2020.07.07 |
---|---|
MSSQL 년도, 주차 구하기, DATEPART (0) | 2020.06.18 |
JULIAN TO DATETIME [줄리안 형식 날짜를 데이트 타임 형식으로 변환] (0) | 2020.06.02 |
[MS-SQL] ASCII / CHAR 변환 (0) | 2020.03.18 |
ZPL QR BARCODE (3) | 2020.01.09 |