Last active
May 22, 2017 07:53
-
-
Save gsbeaton/f34c2493ffc7ff1b40c6a18858e120ce to your computer and use it in GitHub Desktop.
A JavaScript function to convert Unix time (milliseconds since 1 Jan 1970 at 00:00:00) to a Qlik time (days since 30 Dec 1899 at 00:00:00). Correct to the nearest second.
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
/* | |
| ------------------------------------------------------------------- | |
| Unix to Qlik time | |
| ------------------------------------------------------------------- | |
| Convert a unix timestamp to a Qlik timestamp. | |
| | |
*/ | |
var unixToQlikTime = function(){ | |
a = new Date(1899,12,30); //this is Qlik's Epoch date (http://help.qlik.com/en-US/qlikview/12.1/Subsystems/Client/Content/Scripting/DateAndTimeFunctions/date-time-functions.htm). | |
b = new Date(); | |
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); | |
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); | |
var time = ((b.getHours() * 60 * 60) + (b.getMinutes() * 60) + b.getSeconds()) *1000 / (24*60*60*1000); | |
return ((utc2 - utc1) /(24*60*60*1000))+time; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment