Time minus Time

Post Reply
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Time minus Time

Post by Darkhorse »

Hi all

I have a problem where I need to take time away from time but both are in a string value, I have stripped it down to this:
fist time
20131010145020
last time
20131010145060

is there anyway to get diffrence in Seconds format?

im trying to convert it using the DayNo() but reading the help file and numourous attempts at trying to add the time into the string it gives me 19600101000000 which is the default first day minute etc.
Last edited by Darkhorse on Mon Nov 11, 2013 3:15 pm, edited 1 time in total.
Edward Stuart
Community Contributor
Posts: 248
Joined: Tue Nov 01, 2011 10:31 am
OLAP Product: TM1
Version: All
Excel Version: All
Location: Manchester
Contact:

Re: Time minus Time

Post by Edward Stuart »

Have been playing around with something similar recently and this worked for me:

http://www.tm1forum.com/viewtopic.php?p=21974
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: Time minus Time

Post by Darkhorse »

hi this example already is a serial number using Now

its a predetermined Date and Time I have and need to use, so converting back to a time serial number is needed first, I have read alan Kirks info on time and seen dayno is good for getting a serial number but the example only shows using a date going in to it, I have tried many converisons of DayNo but I cannot get a time string in there as well
Edward Stuart
Community Contributor
Posts: 248
Joined: Tue Nov 01, 2011 10:31 am
OLAP Product: TM1
Version: All
Excel Version: All
Location: Manchester
Contact:

Re: Time minus Time

Post by Edward Stuart »

Will TIMST work for you?
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: Time minus Time

Post by Darkhorse »

does this not convert a serial number to a string ?
Alan Kirk
Site Admin
Posts: 6654
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Time minus Time

Post by Alan Kirk »

Darkhorse wrote:Hi all

I have a problem where I need to take time away from time but both are in a string value, I have stripped it down to this:
fist time
20131010145020
last time
20131010145060
Really? Because I've never seen a timestamp that has the seconds as "60". It would normally go to 59 and then increment the minute.
Darkhorse wrote:is there anyway to get diffrence in Seconds format?

im trying to convert it using the DayNo()
Which, as I said in the dates and times thread, returns
DayNo. Input: A date string in TM1 format (YY-MM-DD or (8.4+) YYYY-MM-DD). Output: The TM1 serial date counting from 0 = 1 January 1960.
I didn't say anything about it returning a time component, mainly because it doesn't. If it did, I would have mentioned it. It doesn't matter how many times you pound on the door of that function, it won't return what it's not designed to return.
Darkhorse wrote:but reading the help file and numourous attempts at trying to add the time into the string it gives me 19600101000000 which is the default first day minute etc.
No, it doesn't. It gives you a day. No hours, no minutes, no seconds. Note the absence of non-zero values beyond the 8th character. See above for why.

The solution is to use the basic principle as is contained in the answer that I gave to you in the dates and times thread back in July. You need to parse the strings into components. From these components you can work out the decimal part of the day that the time elements represent using basic maths equations. A day is 1, and hour is 1/24, a minute is 1/24/60 and so on. Once you have both times as date integer components and time decimal components you can subtract one from the other and from that value you can calculate the number of seconds in the decimal value.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: Time minus Time

Post by Darkhorse »

wo there alan,

I said i had stripped the values from the string to a simple string without the ":" and "-" (apologies from putting a 6 in my example unfortuantely I cant seem to copy and paste from my TM1 directly into here (sometimes it works sometimes it doesnt)
I have a problem where I need to take time away from time but both are in a string value, I have stripped it down to this:
fist time
20131010145020
and I said
I have read alan Kirks info on time and seen dayno is good for getting a serial number but the example only shows using a date going in to it, I have tried many converisons of DayNo but I cannot get a time string in there as well
The Value that i said gets returned from Date is 19601010000000 when i tried with coding, Apologies Alan but to get things wrong but its good to try and find a result to fix it, I have been through most of the help file and tried every possible option to turn a string (it can be altered) to a serial value so I can do a simple calculation one time minus second time equals difference is what im looking for.

I understand what your writing in the date time write up 6am is .25 of a day so 1/4 but I was wondering if there was a way to do the times directly as I need to find a way to find the minutes and secondshow does that work?

so really im looking for this

14:50:20-14:45:02 = 5:18
I added the date to the time to create the ability to 1 possible put it into a capsule to create a serial and 2 catch anything that went over the 12am time line
Alan Kirk
Site Admin
Posts: 6654
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Time minus Time

Post by Alan Kirk »

Darkhorse wrote:wo there alan,

I said i had stripped the values from the string to a simple string without the ":" and "-" (apologies from putting a 6 in my example unfortuantely I cant seem to copy and paste from my TM1 directly into here (sometimes it works sometimes it doesnt)
[Ctrl]+[C] multiple times, or use the Copy on the edit menu. If you can't paste it odds are that you aren't really copying it in the first place, which is a known issue in some of the TM1 GUIs.
Darkhorse wrote:
I have a problem where I need to take time away from time but both are in a string value, I have stripped it down to this:
fist time
20131010145020
and I said
I have read alan Kirks info on time and seen dayno is good for getting a serial number but the example only shows using a date going in to it, I have tried many converisons of DayNo but I cannot get a time string in there as well
And why did the example only show a date going into it? Because both Iboglix and I were too lazy to use a time example as well? Because it's a good secret that we decided to keep for ourselves? Or possibly it's because, as the function name (DayNo) implies and the documentation is pretty unambiguous about... it only works with dates; whole days. Note the complete absence of arguments for passing time components to the function. You're getting 19601010000000 because if you're trying to pass in a time component it's evaluating as a bogus date and coming out as zero.
Darkhorse wrote:The Value that i said gets returned from Date is 19601010000000 when i tried with coding, Apologies Alan but to get things wrong but its good to try and find a result to fix it, I have been through most of the help file and tried every possible option to turn a string (it can be altered) to a serial value so I can do a simple calculation one time minus second time equals difference is what im looking for.

I understand what your writing in the date time write up 6am is .25 of a day so 1/4 but I was wondering if there was a way to do the times directly as I need to find a way to find the minutes and secondshow does that work?

so really im looking for this

14:50:20-14:45:02 = 5:18
I added the date to the time to create the ability to 1 possible put it into a capsule to create a serial and 2 catch anything that went over the 12am time line
One other thing that I said is that:
I wrote: Both Excel and TM1 provide functions for obtaining serial dates and times. TM1's set is more limited (and generally more focussed on date to string conversions and vice versa while Excel's tend to be more "value- (numeric) oriented), but many of them have equivalents in some form or another.
Many, not all.

I told you in the reply to your July question (which was in its essence pretty much the same question as this one) that the only option you had to work with timestamps like this was to parse the strings and do the maths. You seem to have a reluctance to do that.

The following is a fully worked example. You can simplify it, you can put it in a generic TI process that can pass back the result through global variables, you can even convert it from a TI to a rules-based value in a control cube. What you cannot do is avoid doing the parsing and calculations in some fashion. Not until or unless Iboglix releases some new TI functions to do this conversion automatically for you, which I wouldn't hold my breath for.

Code: Select all

dbl_1Hour = 1/24;
dbl_1Minute = dbl_1Hour\60;
dbl_1Second = dbl_1Minute\60;

l_SecondsIn1Day = 60*60*24;

#--------------------------------------------------------------------------------------
s_TimeFirst = '20131010145020';

s_DayFirst = Subst( s_TimeFirst, 1, 4)  | '-' |  Subst( s_TimeFirst, 5, 2)  | '-' | Subst(  s_TimeFirst, 7, 2);
l_DayFirst = DayNo(s_DayFirst);

s_HoursFirst = Subst( s_TimeFirst, 9, 2);
s_MinutesFirst = Subst( s_TimeFirst, 11, 2);
s_SecondsFirst = Subst( s_TimeFirst, 13, 2);

dbl_HoursFirst = Numbr( s_HoursFirst) * dbl_1Hour;
dbl_MinutesFirst = Numbr( s_MinutesFirst) * dbl_1Minute;
dbl_SecondsFirst = Numbr( s_SecondsFirst) * dbl_1Second;

dbl_FirstDayTime = l_DayFirst + dbl_HoursFirst + dbl_MinutesFirst + dbl_SecondsFirst;

#--------------------------------------------------------------------------------------
s_TimeSecond = '20131010145059';

s_DaySecond = Subst( s_TimeSecond, 1, 4)  | '-' |  Subst( s_TimeSecond, 5, 2)  | '-' | Subst(  s_TimeSecond, 7, 2);
l_DaySecond = DayNo(s_DaySecond);

s_HoursSecond = Subst( s_TimeSecond, 9, 2);
s_MinutesSecond = Subst( s_TimeSecond, 11, 2);
s_SecondsSecond = Subst( s_TimeSecond, 13, 2);

dbl_HoursSecond = Numbr( s_HoursSecond) * dbl_1Hour;
dbl_MinutesSecond = Numbr( s_MinutesSecond) * dbl_1Minute;
dbl_SecondsSecond = Numbr( s_SecondsSecond) * dbl_1Second;

dbl_SecondDayTime = l_DaySecond + dbl_HoursSecond + dbl_MinutesSecond + dbl_SecondsSecond;


#--------------------------------------------------------------------------------------
dbl_Difference = dbl_SecondDayTime - dbl_FirstDayTime;
l_Seconds = Round( dbl_Difference * l_SecondsIn1Day);

AsciiOutput('F:\Temp\Time.txt', Trim (Str( l_Seconds, 12, 0 ) ) | ' seconds');
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: Time minus Time

Post by Darkhorse »

Thanks alan :D

I have just finished my own using the math approach I left it in the column un stripped and passed each part:

pStartTime = 2013-11-08 21:28:19.002
vTimestamp = 2013-11-08 21:28:23.011


#Start# vElapsedTime= Numbertostring(((
#Day# ((stringtonumber(subst(vTimeStamp,9,2))-stringtonumber(subst(pStartTime,9,2)))*86400)+
#Hour# ((stringtonumber(subst(vTimeStamp,12,2))-stringtonumber(subst(pStartTime,12,2)))*3600)+
#Minutes # ((stringtonumber(subst(vTimeStamp,15,2))-stringtonumber(subst(pStartTime,15,2)))*60)+
#Seconds# (stringtonumber(subst(vTimeStamp,18,2))-stringtonumber(subst(pStartTime,18,2)))))|'.' |
#Milli Sec# numbertostring(if(stringtonumber(subst(vTimeStamp,21,3))-stringtonumber(subst(pStartTime,21,3))<0,
stringtonumber(subst(vTimeStamp,21,3)),stringtonumber(subst(vTimeStamp,21,3))-stringtonumber(subst(pStartTime,21,3))))
#String ending# |'Seconds','');
returns me: 4.009 seconds

Will give yours ago as well.

thanks again, and last time I asked back in june this time thing rocked my head on what was needed. 8 hours adding to current time but fully understand now just wanted to find a quicker solution than all this code!

would of thought something so commonly needed would be so easy to do but hey ho,

and yeah that bloomin copy and paste I find i have to log off the instance and log back in for it to finally sync.. another one of those.. learn to live with problems :?

*edited as the Millisecond was incorrect & Added Day
Post Reply