반응형
Convert Datetime to Unix timestamp
In Microsoft SQL Server 2012 or above, is it possible to convert a datetime value to Unix time stamp in a single select statement? If so, how can it be done?
use db
CREATE FUNCTION 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
SELECT dbo.UNIX_TIMESTAMP(GETDATE()) ;
https://stackoverflow.com/questions/34455408/convert-datetime-to-unix-timestamp
How can I convert UNIX timestamp (bigint) to DateTime in SQL Server?
Select dateadd(S, 1637852002, '1970-01-01')
.
반응형
'프로그래밍 > DataBase' 카테고리의 다른 글
[MSSQL] 특정 기간에 해당하는 모든 날짜 (MASTER..SPT_VALUES) (0) | 2022.02.23 |
---|---|
[MSSQL] Adding string to DATEDIFF(day,getdate(),enddate) as DayRemain how please? (0) | 2022.02.21 |
[DATABASE/POSTGRESQL] 마이그레이션 : SQL Server → PostgreSQL (0) | 2021.10.13 |
[PostgreSQL] 자동 증가 형식 (serial 등), 자동 증가 타입이 설정된 컬럼에 값을 지정하여 데이터를 추가 (0) | 2021.10.12 |
[PostgreSQL] windows 설치 (0) | 2021.09.03 |