Skip to content

Instantly share code, notes, and snippets.

@andreasbotsikas
Last active December 15, 2016 01:26
Show Gist options
  • Save andreasbotsikas/977c6471e073a16ec00544bf9cc55a8b to your computer and use it in GitHub Desktop.
Save andreasbotsikas/977c6471e073a16ec00544bf9cc55a8b to your computer and use it in GitHub Desktop.
SQL convert unix timestamp to date
-- To select min max dates
select
dateadd(S, min([time])/1000, '1970-01-01') as startdate,
dateadd(S, max([time])/1000, '1970-01-01') as enddate
FROM HistoricTable
-- To add a calculated column per row
BEGIN TRANSACTION
GO
ALTER TABLE HistoricTable ADD
ConvertedDate AS (dateadd(second,[time]/(1000),'1970-01-01'))
GO
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment