Created
December 21, 2020 19:20
-
-
Save tonmcg/5e3c049ce925e18bd5ae416d77ee1f75 to your computer and use it in GitHub Desktop.
Power Query M Function to Convert Milliseconds to Date (Datetime)
This file contains 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
(milliseconds as any, optional returnDateTime as nullable text) => | |
let | |
result = | |
if milliseconds <> null then | |
let | |
javaScriptBaseDate = #datetime(1970,1,1,0,0,0), | |
//milliseconds = 1576483200000, | |
isDateTime = if returnDateTime = "false" or returnDateTime = "" then false else true, | |
seconds = milliseconds / 1000, | |
durationInSeconds = #duration(0,0,0,seconds), | |
dateRecord = DateTime.ToRecord(javaScriptBaseDate + durationInSeconds), | |
finalDate = | |
if isDateTime then | |
#datetime(dateRecord[Year],dateRecord[Month],dateRecord[Day],dateRecord[Hour],dateRecord[Minute],dateRecord[Second]) | |
else | |
#date(dateRecord[Year],dateRecord[Month],dateRecord[Day]) | |
in | |
finalDate | |
else | |
null | |
in | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment