Hi,@Edu_Mohd
Welcome to Microsoft T-SQL Q&A Forum!
The prerequisite for this is that the unix format must be correct.Try this:
SELECT columnA,Convert(varchar,DATEADD(MILLISECOND, CAST(RIGHT(dateTime, 3) AS INT)
- DATEDIFF(MILLISECOND,GETDATE(),GETUTCDATE()), DATEADD(SECOND, CAST(LEFT(dateTime, 10) AS INT), '1970-01-01')),111)as FormatedDate
From mainTable where ...
Test code:
create table #test01
(
dateTime BIGINT
)
insert into #test01 values(1633418069),
(1633504469),
( 1633590869),
(1665126869)
SELECT Convert(varchar,DATEADD(MILLISECOND, CAST(RIGHT(dateTime, 3) AS INT)
- DATEDIFF(MILLISECOND,GETDATE(),GETUTCDATE()), DATEADD(SECOND, CAST(LEFT(dateTime, 10) AS INT), '1970-01-01')),111)as FormatedDate from #test01
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.