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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
MCANTAL1639145723
Contributor
Contributor

Define if time is between 2 hours

Hi,

I need to know if the time of an existing date format (example 2022-07-28 02:32:00) is between 00:00:00 and 05:15:00.

I don't know how to do in TMAP, someone could help me ?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

@M CANTAL​ , no a function we can use directly to compare the time of a date if it is between a time range, here I create a function in a user routine to do it.

package routines;

 

import java.util.Calendar;

import java.util.Date;

 

public class MyRoutine {

 

 

 

  public static boolean compareTime(Date param1) {

  

   Calendar calendar = Calendar.getInstance();

   calendar.setTime(param1);

   int hour = calendar.get(Calendar.HOUR_OF_DAY);

   int minute = calendar.get(Calendar.MINUTE);

   int second = calendar.get(Calendar.SECOND);

    Date startDate=TalendDate.parseDate("HH:mm:ss","00:00:00");

    Date endDate=TalendDate.parseDate("HH:mm:ss","05:15:00");

    Date inputDate=TalendDate.parseDate("HH:mm:ss",""+hour+":"+minute+":"+second);

 

    

    if(TalendDate.compareDate(inputDate, startDate)!=-1&&TalendDate.compareDate(inputDate, endDate)!=1){

     return true;

    }else {

     return false;

    }

    

    

  }

}

 

This function requires an input parameter with Date type and it returns a booelan value (true or false);

Then, we can call this function on tMap, here is an example.

0695b00000StTIzAAN.png0695b00000StTJ4AAN.png 

Hope it helps you!

 

Regards

Shong

 

View solution in original post

3 Replies
Anonymous
Not applicable

Only the time part needs to be compared, not the date part?

 

MCANTAL1639145723
Contributor
Contributor
Author

Yes, only the time part

Anonymous
Not applicable

@M CANTAL​ , no a function we can use directly to compare the time of a date if it is between a time range, here I create a function in a user routine to do it.

package routines;

 

import java.util.Calendar;

import java.util.Date;

 

public class MyRoutine {

 

 

 

  public static boolean compareTime(Date param1) {

  

   Calendar calendar = Calendar.getInstance();

   calendar.setTime(param1);

   int hour = calendar.get(Calendar.HOUR_OF_DAY);

   int minute = calendar.get(Calendar.MINUTE);

   int second = calendar.get(Calendar.SECOND);

    Date startDate=TalendDate.parseDate("HH:mm:ss","00:00:00");

    Date endDate=TalendDate.parseDate("HH:mm:ss","05:15:00");

    Date inputDate=TalendDate.parseDate("HH:mm:ss",""+hour+":"+minute+":"+second);

 

    

    if(TalendDate.compareDate(inputDate, startDate)!=-1&&TalendDate.compareDate(inputDate, endDate)!=1){

     return true;

    }else {

     return false;

    }

    

    

  }

}

 

This function requires an input parameter with Date type and it returns a booelan value (true or false);

Then, we can call this function on tMap, here is an example.

0695b00000StTIzAAN.png0695b00000StTJ4AAN.png 

Hope it helps you!

 

Regards

Shong