I would like to change decimal minutes into HH:mm:ss (DAX, Tabular Cube).
When I use this :
measure = FORMAT(TIME(0;minutes;0);"HH:mm:ss")
I get hours and minutes but without seconds. Minutes are rounded.
When I use this :
measure = FORMAT(TIME(0;0;minutes*60);"HH:mm:ss")
I have an error that value is too big or too small.
Thanks in advance.
DAX understands decimal time in units of days, so all that you need to do is convert decimal minutes to decimal days and format:
FORMAT ( [Minutes] / 60 / 24, "HH:mm:ss" )
Related
Can anyone explain how to convert a Hex TimeDateStamp DWORD value into human readable format?
I'm just curious as to how a value such as 0x62444DB4 is converted into
"Wednesday, 30 March 2022 10:31:48 PM"
I tried googling of course and could not find any explanation. But there are online converters available.
But I'm just interested in converting these values for myself.
Your value is a 32-bit Timestamp.
Your datetime value is a 32-bit Unix Timestamp: The number of seconds since 1/1/1970.
See https://unixtime.org/
In most programming languages you can work with the hexadecimal notation directly.
Implementation should not be done by one person alone, since a lot of engineering goes into it. Leap years, even leap seconds, timezones, daylight savings time, UTC... all these things need to be addressed when working with a timestamp.
I have added my rough calculation below as a demonstration. Definitely use an existing package or library to work with timestamps.
See the JavaScript code below for demonstration.
There I multiply your value by 1000 because JavaScript works in Milliseconds. But otherwise this applies the same to other systems.
let timestamp = 0x62444DB4;
let dateTime = new Date(timestamp * 1000);
console.log('Timestamp in seconds:', timestamp);
console.log('Human-Readable:', dateTime.toDateString() + ' ' + dateTime.toTimeString());
// Rough output, just for the time.
// Year month and day get really messy with timezones, leap years, etc.
let hours = Math.floor(timestamp/3600) % 24;
let minutes = Math.floor(timestamp/60) % 60;
let seconds = Math.floor(timestamp) % 60;
console.log('Using our own time calculation:', hours + ':' + minutes + ':' + seconds);
I have following ruby code to get current time in "milliseconds", for example: 1648059542287 which is equivalent to Wed Mar 23 2022 18:19:02
What I need is timestamp rounded to nearest 30 seconds, for above example, I need it rounded to 1648059540000. Any suggestions?
#ctime = Time.now.to_f
(#ctime * 1000).to_i
Using the time you provided, I think this will do what you want:
Take your time, convert it to an integer
divide by floating point value 30 the number of half minutes
round that value and multiple by 30 to get back to the number of seconds
Create a new time object based on the rounded value.
input = Time.at(1648059542,287000)
Time.at((input.to_i / 30.0).round * 30)
I am having trouble converting a 9.3 decimal variable to minutes. The variable is showing as a fraction of an hour and I need that to show as minutes.
Here is an example below of what needs to be converted.
DECSNTIME
0.039
1.279
6.801
Convert the decimal hours to seconds, and format the value for time display.
data have;
input decsntime ##;
cards;
0.039 1.279 6.801
run;
data want;
set have;
minutes = decsntime * 60; * plain minutes might be enough, depends on analysis;
time = decsntime * 3600; * sas time value;
format time time5.;
run;
proc report data=want;
columns decsntime minutes time time=timehms time=timehmsd;
define decsntime / 'Time/(hours)' display;
define time / 'Time/(H:M)';
define timehms / format=time8. 'Time/(H:M:S)';
define timehmsd / format=time11.2 'Time/(H:M:S.D)';
run;
As mentioned in the comment by #Richard are you looking for something as simple as the following? If not then please edit your question to give more explanation and examples of data before and after the conversion from hours to minutes.
data have;
input hours;
datalines;
9.3
0.039
1.279
6.801
1
1.5
2
;
data want;
set have;
minutes = hours * 60;
run;
So in the game World of Warcraft I have managed to get the remaining time of a mission via their API. The problem for me is that I want to convert this to seconds to then be able to check at which time the mission will finish. If I call the function time() in the game I get a response similar to this 1418569973 which to me, makes no sense. But this is why I need to convert it to seconds, because then I can simply add the amount of seconds I get to the current time and get the end time of the mission.
But my problem is that the when I look into the table that gives me the current time left of a mission it returns a string with the format "X h X min" for example "4 h 34 min". I need to convert that to seconds but I literally have no idea on where to start. I'm thinking of something like removing the "h" and the "min" in a function. But from there I'm not really sure of where to go.
os.time() returns the seconds since epoch. Thus, "1418569973" gives you "12/14/14 03:12:53 PM" UTC. Now, to convert your string to seconds:
local iH, iM = sInput:match "(%d+) h (%d+) min"
iH, iM = tonumber( iH ), tonumber( iM )
local iSec = iH * 3600 + iM * 60
Suppose I have an ISO 8601 duration, expressed as "P1M". Phrased colloquially, this means "one month." Is there a standard rule for converting this into a number of seconds, assuming the start date is not known?
For 30-day months, it might be 2,592,000.
For 31-day months, it might be 2,678,400.
In February, it might be 2,419,200 or it might be 2,505,600.
My gut says there's no way to resolve "one month" to an exact number of seconds without knowing context, and where those seconds are laid out on the calendar. But are there standard rules/conventions to calculate these durations in an abstract way?
From ISO 8601 documentation that I found (page 6 - http://xml.coverpages.org/ISO-FDIS-8601.pdf), it seems you are correct in that the number of seconds in a month cannot definitively be determined. However it does note that "In certain applications a month is regarded as a unit of time of 30 days", so depending on your application this may be a valid approach.
The distinction between "Calendar Time" (Years, Months, etc) and "Absolute Time" (Hours, Minutes, Seconds, etc) is sometimes an important one. As an example, some people might complain about having 13 mortgage payments some years if they paid every 30 days as opposed to every month.
You are right, an ISO 8601 duration is dependent of the context.
A duration is a period/an interval of time between two dates.
Example :
2020-01-01/2020-02-01 = P1M = P31D
2020-02-01/2020-03-01 = P1M = P29D
2019-02-01/2019-03-01 = P1M = P28D
If you want a fixed duration indepedent of the context, use the day notation P30D, P60D, P90D... instead.
The same applies for years :
2019-01-01/2020-01-01 = P1Y = P12M = P365D
2020-01-01/2021-01-01 = P1Y = P12M = P366D
If you can't have context information about a duration, for example P1M retrieved from database or given by user input, use by default today's context.
//What is a duration of one month in seconds ?
P1M = ? (no context)
//Use default context
Today = 2020-03-31
2020-03-31/P1M = 2020-03-31/2020-04-30
=> P1M = P30D
//A month contains 2 592 000 seconds