Last active
          July 5, 2018 05:54 
        
      - 
      
- 
        Save bradbrowne/0839ef41f7430d0496e05ce64b6c3a0f to your computer and use it in GitHub Desktop. 
    Convert Epoch milliseconds as used by Javascript Date object and Unix timestamps to Local Standard Time via T-SQL for SQL Server
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | declare @epochMilliseconds bigint | |
| set @epochMilliseconds = 1530769196903 | |
| declare @utcDateTime datetime | |
| select @utcDateTime = DATEADD(MS, @epochMilliseconds%(3600*24*1000), DATEADD(DAY, @epochMilliseconds/(3600*24*1000), '1970-01-01 00:00:00.000')) | |
| --The result is 2018-07-05 05:39:56.903 | |
| select CONVERT(datetime, SWITCHOFFSET(@utcDateTime, DATEPART(TZOFFSET, @utcDateTime AT TIME ZONE 'AUS Eastern Standard Time'))) AS [AUS Eastern Standard Time] | |
| --The result is 2018-07-05 15:39:56.903 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment