Page 1 of 1

Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 8:31 am
by Darkhorse
Hi all

Ive read all there is on the TIME and date piece Written by Alan, but im still struggling to find what i need.

My server is 8 hours behind due to the location of the server and the timezone it sits in.
I have created a TI that collects data from a monitoring cube and trying to get it in to another cube at GMT time,

I need the Date and the hour the problem i have is if i simply subst TIME and add 8 then it works fine until it goes past the Day.

i.e
server time is 17:00
Date on server is 28/07/13

if i add 8 to the time
New Time 01:00
Date on server is 28/07/13

I understand i can write a complex if system, to get it correct, but I was wondering if there was a quicker alternative rather than using IFs

thanks

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 9:52 am
by whitej_d
Can you just convert everything to a serial time and use that to add the 8 hours. Just add 1/3 to the serial time.

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 10:23 am
by Darkhorse
Only just starting to play with the "Time Features" (never had a need to till now) I dont fully understand the add 1/3 sorry can you explain a little more?

I wrote this based on Alan Kirks writeup

does anyone have any pointers because this does not work when converting it back..

s_TimeStamp1 = TimSt (Now, '\Y\m\d\h\i\s');
s_TimeStamp2 =Stringtonumber(s_TimeStamp1 );
s_TimeStamp3= 8;
s_TimeStamp4= s_TimeStamp2+ s_TimeStamp3;
s_TimeStamp5 = numbertostring(s_TimeStamp4);
s_TimeStamp6= TimSt (s_TimeStamp4, '\Y \M \d \h \i \s');

asciioutput(exportfile1,s_TimeStamp1,s_TimeStamp6);

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 10:26 am
by Wim Gielis
Darkhorse wrote:Only just starting to play with the "Time Features" (never had a need to till now) I dont fully understand the add 1/3 sorry can you explain a little more?
As 1 day (24 hours) stands for a value of 1, 8 hours will be equal to 1/3.

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 11:07 am
by Darkhorse
Wim can i be a little cheeky and ask for an example of how to write that?

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 6:22 pm
by Wim Gielis
Darkhorse wrote:Wim can i be a little cheeky and ask for an example of how to write that?
Come on, you must be kidding.

For example, the Now function gives you a serial number.
Adding 8 hours to that just means that you need to do:
+1/3

It's as simple as that.

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 6:25 pm
by bplaia
Darkhorse wrote:Wim can i be a little cheeky and ask for an example of how to write that?
Hey guys, first time posting on TM1Forum, you guys have been an invaluable source of information during my TM1 training days.

Darkhorse, it looks like you're trying to add 8 directly to the serial date number. In the serial date, hours and minutes are fractions of 1, so 6 hours would be 0.25 or 6/24 and 8 hours would be 1/3 or 8/24. I would suggest this method for reaching the serial date you desire.

Code: Select all

nSerialDateNow = NOW;
nSerialDate8HoursFromNow = nSerialDateNow + (8/24);
s_TimeStamp1 = TimSt (nSerialDateNow, '\Y\m\d\h\i\s');
s_TimeStamp2 = TimSt (nSerialDate8HoursFromNow, '\Y\m\d\h\i\s');
where s_TimeStamp1 would be the formatted date/time string for NOW and s_TimeStamp2 would be the formatted date/time string for 8 hours from NOW

Cheers,
Brian

Re: Increasing Time by 8 hours

Posted: Mon Jul 29, 2013 6:55 pm
by Alan Kirk
Darkhorse wrote:Only just starting to play with the "Time Features" (never had a need to till now) I dont fully understand the add 1/3 sorry can you explain a little more?

I wrote this based on Alan Kirks writeup
Loosely based, I think, because...
Darkhorse wrote:does anyone have any pointers because this does not work when converting it back..

s_TimeStamp1 = TimSt (Now, '\Y\m\d\h\i\s');
s_TimeStamp2 =Stringtonumber(s_TimeStamp1 );
Nowhere in the article do I suggest that the above would work, nor do I even mention the StringToNumber function. And this is for a very good reason; StringToNumber is not a "smart" function. It's not designed to look at a string, think "Oh, that looks like a date and time, I'll convert it to a serial date". All it does is take any numeric characters or digit group or decimal separators (such as commas and decimal points, respectively) and try to convert them into a corresponding number. StringToNumber will never see the string "2013" as the 2013th year of the common calendar. It only sees it as the characters "2", "0", "1" and "3" to be converted into the number 2013.

Although you've used Now() in your example I'm assuming (based on your other question) that you in fact want a generic way of converting a timestamp string. To do such a conversion you have to do what I mentioned (including in my answer to your question) in the crib thread; you have to parse the string into day, month, year, hour etcetera components using the SubSt function. The date components will get you a serial date via the DayNo function, the time you have to work out for yourself as I described in this post. IBM has not provided a function for converting a timestamp string directly into a serial date value (Now() does not do this, it simply returns the current serial date and time), and StringToNumber certainly isn't that function. Your code isn't working because you're trying to take a shortcut that doesn't exist.

Re: Increasing Time by 8 hours

Posted: Tue Jul 30, 2013 12:20 am
by Darkhorse
Aha well that answers that one,

Sorry Alan as I said I'm totally new to the time section, the most I've ever really done is dissect Today/now for parts of the date and time, in vb this would be a dodle but the tm1 functions are extremely complex I've been looking for examples all over the place and your write up is quite a head scratcher for a newby :D

Re: Increasing Time by 8 hours

Posted: Tue Jul 30, 2013 12:24 am
by Darkhorse
Darkhorse wrote:Aha well that answers that one,

Sorry Alan as I said I'm totally new to the time section, the most I've ever really done is dissect Today/now for parts of the date and time, in vb this would be a dodle but the tm1 functions are extremely complex I've been looking for examples all over the place and your write up is quite a head scratcher for a newby :D
Thank you all I will try the example above tomorrow appreciate the help all yet again this site comes thru ;)