FILTER - MX

Java on dates

JDate: Date/time

Don't forget to check the documentation for the JDate Class

Filter lines before a fixed date

JDate jDate1=_doJava.getNewJDate();
if (!jDate1.set(_str1))
  return "";

JDate jDate2=_doJava.getNewJDate("20190201_000000");

if (jDate1.getTimeInMillis()<jDate2.getTimeInMillis())
return true;
//will suppress dates before 20190201_000000;
return false;
//will keep dates after 20190201_000000;

Filter lines after a time delay

If you want to filter lines with a datetime > 30 days

double delai_days = 30.0;
JDate jDate=_doJava.getNewJDate();
if (!jDate.set(_str1))
  return "";
if ((System.currentTimeMillis() - jDate.getTimeInMillis()) > (delai_days * 24.0*60.0*60.0*1000.0))
  return true;
    return false;

If you want to filter lines with a datetime > 20 years

double delai_years = 20.0;

JDate jDate=_doJava.getNewJDate();
if (!jDate.set(_str1))
  return "";

if ((System.currentTimeMillis() - jDate.getTimeInMillis()) > (delai_years * 365.25 *24.0*60.0*60.0*1000.0))
  return true;
else
  if((System.currentTimeMillis() - jDate.getTimeInMillis()) < 0.0)
    return true;
  else
    return false;

Filter lines in the future

JDate jDate1=_doJava.getNewJDate();
if (!jDate1.set(_str1))
  return true;

if (jDate1.getTimeInMillis() > System.currentTimeMillis())
return true;
return false;

Was this article helpful?

Powered by Zendesk