Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

Transform a time into seconds

Hi!
I am trying in the tMap to transform a time that I get out from a data source in string like this "12:13:55" to seconds (43200 + 720 + 55 = 43975) in this case.
How can I do that with the expressions given to me in the tMap Expressions?
Thanks
Joakim
Labels (2)
9 Replies
Anonymous
Not applicable

Hi,
Create a routine :-
public static String CalculateTotalSeconds(String timein) {
String[] date_string = timein.split(":");
int hours = Integer.parseInt(date_string);
int mins = Integer.parseInt(date_string);
int seconds = Integer.parseInt(date_string);

int totalsec = (hours * 3600)+ (mins* 60) + seconds;

return "" + totalsec;
}
Call from tmap :-
Date_Converter.CalculateTotalSeconds(variable);
Returns a string with total seconds.
HTH
_AnonymousUser
Specialist III
Specialist III
Author

tnewman: Thanks for the example. I just don´t know how to create a routine, I am in the Navigator mode of the Repository but I dont understand how to create it.
// Joakim
_AnonymousUser
Specialist III
Specialist III
Author

I dont have the "code" section in my Repository that is shown on examples I have seen... How do I get that visible?
Anonymous
Not applicable

Hi,
I am using TIS and I see the Code branch in the standard view. I have looked around the various menus and cannot see anywhere we you can include/exclude from the repo view.
I am not sure if TOS is different.
Sorry I can't be much more help - maybe someone else can answer.
Anonymous
Not applicable

It's in TOS too, at least for java projects.
Karuetl
Creator II
Creator II

Got an error when creating routine 

 

0683p000009M34s.png

 

 

vapukov
Master II
Master II


@Karuetl wrote:

Got an error when creating routine 

 


you just need chose array element for parse

0 - hours

1 - minutes

2 - seconds

	public static String CalculateTotalSeconds(String timein) {
		String[] date_string = timein.split(":");
		int hours = Integer.parseInt(date_string[0]);
		int mins = Integer.parseInt(date_string[1]);
		int seconds = Integer.parseInt(date_string[2]);

		int totalsec = (hours * 3600)+ (mins* 60) + seconds;

		return "" + totalsec;
		} 

 

 

P.S.

keep in mind - original routine return String, if you need have a long or integer - you need modify it or convert into integer in tMap/tJava

Karuetl
Creator II
Creator II

Thanks 

vapukov
Master II
Master II

thanks - it is too much  ...  kudu is enough 😉

 

welcome to community