Skip to content

Instantly share code, notes, and snippets.

@tonmcg
Last active May 6, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonmcg/6662024b3221d04944678bdfecac445b to your computer and use it in GitHub Desktop.
Save tonmcg/6662024b3221d04944678bdfecac445b to your computer and use it in GitHub Desktop.
Convert to Power Query M Duration from JavaScript Milliseconds
(s as number) as duration =>
let
// patterned after https://stackoverflow.com/a/9763769/4637650
// s = 28860000, //481 minutes
ms = Number.Mod(s,1000),
t = (s - ms) / 1000,
secs = Number.Mod(t,60),
r = (t - secs) / 60,
mins = Number.Mod(r,60),
hrs = (r - mins) / 60,
dur = #duration(0,hrs,mins,secs)
in
dur
@FrankFromGermany
Copy link

(s as number) as duration =>
#duration(0, 0, 0, s/1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment